Repository navigation
Fix lazy dynamic import reloads and module evaluation - #101937
Conversation
|
Vercel Agent's latest review does not approve this pull request under the repository's review policy. Explanation
@mischnic and @wbinnssmith: the merge-base policy still calls for owner review because this PR combines the medium core-algorithm trigger ( Resolved issues (1)
|
Tests PassedCommit: 887059b |
24e03cc to
38662a8
Compare
38662a8 to
14db82c
Compare
Vercel Agent's latest review does not approve this pull request under the repository's review policy.
5ba70f6 to
aedbb63
Compare
Activating a lazy dynamic import changes the client output, which advances the HMR version without the client missing an update. The chunk list it then loads subscribes with the client's older version, and the version check reloaded the page. Check the version once per connection, on its first versioned subscription. That catches updates missed through stale HTML or a dropped connection. Later mismatches are skipped, since lazy compilation can advance the version without the client missing an update. <!-- NEXT_JS_LLM -->
When a dynamic import target is already available, use the parent import to return an ESM namespace instead of raw CommonJS exports.
Webpack loaders evaluate importModule graphs in a separate process that cannot activate lazily compiled dynamic imports. Resolve those graphs in an asset context without lazy compilation.
Turbopack sends no client update for this navigation and only logs a no-op rebuild when compiling the page exceeds its suppression delay. Assert the Fast Refresh log only for webpack.
Forking the asset context without lazy compilation processed every module reachable from an importModule target a second time, and the copies had the same idents (and so module ids) as the originals. Keep the shared asset context and build the importModule graph with the new `ModuleGraphOptions::force_activated`, which treats activatable modules as activated in that graph only: it walks the `ActivatableModule::activated_references` of lazy compilation proxies, and the proxies generate their active code without depending on the activation state. The importModule fixture now checks that a module imported by both the app and the loader is processed as often as one only the app imports.
primary_chunkable_referenced_modules already falls back to Module::references for modules that aren't activatable, so pass force_activated through unchanged.
98cdc92 to
887059b
Compare
|
Important Needs a person: this repository’s review rules call for a person’s review. Why?
The author is a team member but owns none of the touched areas. Two medium triggers apply: a change to the module graph traversal and the ActivatableModule trait (a core data structure and algorithm), and a change to HMR message handling in the Turbopack hot reloader (the dev-server-and-hmr rubric's medium signal). Two medium triggers escalate on their own. On top of that, the HMR fix in runtime code has no regression test that fails without it, and its described mechanism doesn't match the diff. The repository context script ran without errors (162 implementation lines, under the 600-line threshold).
Review requested from: wbinnssmith, devjiwonchoi, sokra. Facts from the base’s Summary
Fixes for lazy dynamic imports in Turbopack dev. The hot reloader now checks the client's HMR version only on the first versioned Questions for the author (2)
Issues (2)
Checked (4)
Review steps
Read the full report ↗ (Download report.json • report.md) Confirmed: its repro failed on this commit and not the same way on the base. Unverified: a person should judge it. |
There was a problem hiding this comment.
Vercel Agent Verified Review reviewed 887059b and isn’t approving it: this repository’s review rules call for a person’s review. 2 open findings are listed in its review summary and inline. View the full report
| // are skipped, since lazily compiling a chunk list advances the version without the | ||
| // client missing an update. | ||
| const state = clientStates.get(client) | ||
| if ( |
There was a problem hiding this comment.
Note
Unverified · Major — HMR fix doesn't match its description and has no regression test
The description says the false-reload fix "advance[s] the output version immediately while tracking the version clients must have separately" and also avoids server component refreshes. The diff does neither: it adds a per-connection hmrVersionChecked flag and skips the version check on every later subscription. No added or changed test reaches this path: the only HMR test change (test/development/app-hmr/hmr.test.ts) removes an assertion for Turbopack. REVIEW.md's bugfix-regression-test rule (strong for packages/next/src/server/**) asks for a test that fails without the fix, and bugfix-root-cause asks that the described cause match the diff.
Needs your judgment: the review traced this through the code but couldn’t run anything to prove it.
| ) | ||
| // Turbopack sends no client update for this navigation, and only logs a no-op rebuild when | ||
| // compiling the page takes longer than its suppression delay. | ||
| if (!isTurbopack) { |
There was a problem hiding this comment.
Note
Unverified · Minor — Turbopack Fast Refresh log assertion dropped instead of made deterministic
Under Turbopack the test no longer requires the '[Fast Refresh] done in' log, so for Turbopack it now checks only the negative assertion. This is the bundler-keyed assertion skip that REVIEW.md's no-fake-greens rule names. It is justified by a comment, so it counts as a justified medium, but the navigation's Turbopack behavior is no longer asserted at all.
Needs your judgment: the review traced this through the code but couldn’t run anything to prove it.
## Summary Enable `experimental.turbopackLazyDynamicImports` and `experimental.turbopackLazyDynamicImportsSSR` by default in development so dynamic import targets are compiled only when used. Stacked on #101937, which contains the prerequisite bugfixes and should merge first. This layer changes only the defaults and their test expectations: the HMR client adds its own manifest chunk list, and the SSR `next/dynamic` entry uses a manifest loader. Explicit `false` still disables either flag. Production behavior is unchanged. ## Verification - The combined implementation previously passed CI in run 43967218926, attempt 2. - The combined branch tree is unchanged by this split. No local tests were rerun for the branch-only restructuring. <!-- NEXT_JS_LLM -->
…" (#102379) ## Summary Reverts #101873, which was merged before it was ready. `experimental.turbopackLazyDynamicImports` and `experimental.turbopackLazyDynamicImportsSSR` go back to being off by default in development, and the related docs and test expectations are restored. The bugfixes from #101937 are kept. This only reverts the default change. ## Verification - Clean `git revert` of 59490df - Not run: local tests (relying on CI) <!-- NEXT_JS_LLM -->
What?
Extract the bugfixes from #101873 so they can merge before lazy dynamic imports are enabled by default. Both defaults remain unchanged.
Why?
Lazy imports can cause false reloads, return the wrong module namespace, or fail during loader evaluation when explicitly enabled.
How?
turbopack-subscribe, which still catches updates missed through stale HTML or a dropped connection (a reconnect is a new connection and is checked again). Later mismatches on the same connection are ignored, since compiling a lazy chunk list advances the version without the client missing an update.this.importModule()graphs, because loader evaluation runs in a separate process that cannot activate lazy imports. The graph is built with a newModuleGraphOptions::assume_activatedthat follows the targets of lazy-import proxies, and those proxies generate their loading code in such graphs. Modules stay shared with the app instead of being processed a second time in a copy of the asset context. Explicitly enable both lazy-import flags in the existing loader fixture so its nested dynamic-import assertions cover this independently of the defaults, and check that a module imported by both the app and the loader is processed only as often as one that only the app imports.Verification
pnpm test-dev-turboon the importModule suite and thelazy-dynamic-imports,lazy-dynamic-nested-importsandlazy-dynamic-chunk-list-collisionsuites;pnpm test-start-turboandpnpm test-dev-webpackon the importModule suite.