Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable HMR updates even when critical issues occur #3714

Merged
merged 1 commit into from
Feb 10, 2023

Conversation

alexkirsz
Copy link
Contributor

This enables HMR updates, even when the update message also contains critical issues.

There were some inconsistencies with the logic previously, so I'm not sure whether this fix is fully correct. More on that in PR comments.

@alexkirsz alexkirsz requested a review from a team as a code owner February 9, 2023 10:13
@vercel
Copy link

vercel bot commented Feb 9, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
turbo-site ✅ Ready (Inspect) Visit Preview Feb 9, 2023 at 10:13AM (UTC)
9 Ignored Deployments
Name Status Preview Updated
examples-basic-web ⬜️ Ignored (Inspect) Feb 9, 2023 at 10:13AM (UTC)
examples-cra-web ⬜️ Ignored (Inspect) Feb 9, 2023 at 10:13AM (UTC)
examples-designsystem-docs ⬜️ Ignored (Inspect) Feb 9, 2023 at 10:13AM (UTC)
examples-kitchensink-blog ⬜️ Ignored (Inspect) Feb 9, 2023 at 10:13AM (UTC)
examples-native-web ⬜️ Ignored (Inspect) Feb 9, 2023 at 10:13AM (UTC)
examples-nonmonorepo ⬜️ Ignored (Inspect) Feb 9, 2023 at 10:13AM (UTC)
examples-svelte-web ⬜️ Ignored (Inspect) Feb 9, 2023 at 10:13AM (UTC)
examples-tailwind-web ⬜️ Ignored (Inspect) Feb 9, 2023 at 10:13AM (UTC)
examples-vite-web ⬜️ Ignored (Inspect) Feb 9, 2023 at 10:13AM (UTC)

@@ -284,8 +284,6 @@ function handleSocketMessage(msg: ServerMessage) {
const hasCriticalIssues = handleIssues(msg);
const aggregatedMsg = aggregateUpdates(msg, hasCriticalIssues);

if (hasCriticalIssues) return;

Copy link
Contributor Author

@alexkirsz alexkirsz Feb 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aggregateUpdates specifically adds an empty chunk with update to chunksWithUpdates when hasCriticalIssues = true with the following comment:

add an empty record to make sure we don't call onBuildOk

Which means it expects the function to continue below and not stop here.

I'm seeing the same issues being reported in both type: "issues" and type: "partial" updates (and these issues are pretty much duplicated for every message received, no matter the chunk), so I also think something's wrong there. There might be a critical error to one chunk, but since it's reported on every single chunk, we disable updating for all of them.

For now this is enough to re-enable HMR updates.

@ForsakenHarmony WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is that we might get ourselves into a worse situation if we update and the chunk contains an unparseable item which then requires a hard reload

We need to figure improve what / how we report a critical issue

Copy link
Member

@sokra sokra Feb 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should show the error overlay, but queue up the update. Only if you close the error overlay, it will apply the change. Or if another update happens that gets rid of the error.


That what I wrote in the other issue:

Currently HMR updates are ignored when they contain a critical issue.

This has two problems:

  • We might miss updates to unrelated modules
  • Hiding the error overlay with compile errors will still render HMR non-functional

But we still don't want to trash the whole page with an temporary compile error.

Instead HMR updates with critical errors should be collected and be applied once the error overlay is hidden (or the errors disappear).

Error overlay should re-appear when new critical errors arrive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the fact that HMR issues are duplicated on every single chunk? There might be chunks where it is unsafe to update because of fatal issues, but other chunks should be fine. Right now, all chunks are considered as "hard error".

@sokra's solution sounds good to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HMR issues are only duplicated if a chunk depends on another chunk that has the original issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it.

I'll implement @sokra's workaround (i.e. if a user dismisses the overlay, we expect them to be okay with their app breaking).

Can I remove the "add an empty record to make sure we don't call onBuildOk" logic?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out onBuildOk does nothing at this point, could probably remove that event

we could remove the empty record, and make the calls to onBeforeRefresh & onRefresh dependent on whether the error overlay was dismissed as well

when implementing the workaround, treat the overlay directory as a separate package that we consume (i.e. no imports into another package) to make it easier to merge the overlay with the next.js one later on

@github-actions
Copy link
Contributor

github-actions bot commented Feb 9, 2023

⚠️ CI failed ⚠️

The following steps have failed in CI:

  • Turbopack Rust tests (mac/win, non-blocking)

See workflow summary for details

@github-actions
Copy link
Contributor

github-actions bot commented Feb 9, 2023

Benchmark for 3846e5c

Test Base PR % Significant %
bench_startup/Turbopack RSC/1000 modules 2345.07ms ± 7.59ms 2377.52ms ± 7.94ms +1.38% +0.06%
Click to view full benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 8476.35µs ± 83.17µs 8465.99µs ± 55.50µs -0.12%
bench_hmr_to_commit/Turbopack RCC/1000 modules 8659.53µs ± 80.36µs 8794.32µs ± 91.70µs +1.56%
bench_hmr_to_commit/Turbopack RSC/1000 modules 463.60ms ± 1.71ms 464.27ms ± 1.54ms +0.15%
bench_hmr_to_commit/Turbopack SSR/1000 modules 8572.42µs ± 103.87µs 8671.89µs ± 96.69µs +1.16%
bench_hmr_to_eval/Turbopack CSR/1000 modules 7588.94µs ± 61.94µs 7514.25µs ± 96.01µs -0.98%
bench_hmr_to_eval/Turbopack RCC/1000 modules 7719.40µs ± 58.78µs 7725.63µs ± 84.32µs +0.08%
bench_hmr_to_eval/Turbopack SSR/1000 modules 7638.36µs ± 86.86µs 7707.47µs ± 44.45µs +0.90%
bench_hydration/Turbopack RCC/1000 modules 4075.97ms ± 11.12ms 4080.88ms ± 12.46ms +0.12%
bench_hydration/Turbopack RSC/1000 modules 3646.27ms ± 14.44ms 3676.19ms ± 21.04ms +0.82%
bench_hydration/Turbopack SSR/1000 modules 3567.93ms ± 16.68ms 3541.88ms ± 16.37ms -0.73%
bench_startup/Turbopack CSR/1000 modules 2713.95ms ± 12.88ms 2681.70ms ± 10.96ms -1.19%
bench_startup/Turbopack RCC/1000 modules 2468.71ms ± 6.48ms 2484.71ms ± 6.41ms +0.65%
bench_startup/Turbopack RSC/1000 modules 2345.07ms ± 7.59ms 2377.52ms ± 7.94ms +1.38% +0.06%
bench_startup/Turbopack SSR/1000 modules 2056.80ms ± 2.76ms 2070.62ms ± 10.54ms +0.67%

Copy link
Member

@sokra sokra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging this for now until a more user friendly solution is implemented

@sokra sokra merged commit e10e580 into main Feb 10, 2023
@sokra sokra deleted the alexkirsz/web-576-hmr-updates branch February 10, 2023 12:30
jridgewell pushed a commit to vercel/next.js that referenced this pull request Mar 10, 2023
…3714)

This enables HMR updates, even when the update message also contains
critical issues.

There were some inconsistencies with the logic previously, so I'm not
sure whether this fix is fully correct. More on that in PR comments.
sokra pushed a commit to vercel/next.js that referenced this pull request Mar 13, 2023
…3714)

This enables HMR updates, even when the update message also contains
critical issues.

There were some inconsistencies with the logic previously, so I'm not
sure whether this fix is fully correct. More on that in PR comments.
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 25, 2024
…3714)

This enables HMR updates, even when the update message also contains
critical issues.

There were some inconsistencies with the logic previously, so I'm not
sure whether this fix is fully correct. More on that in PR comments.
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 29, 2024
…3714)

This enables HMR updates, even when the update message also contains
critical issues.

There were some inconsistencies with the logic previously, so I'm not
sure whether this fix is fully correct. More on that in PR comments.
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Aug 1, 2024
…3714)

This enables HMR updates, even when the update message also contains
critical issues.

There were some inconsistencies with the logic previously, so I'm not
sure whether this fix is fully correct. More on that in PR comments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants