Repository navigation
fix(code-splitting): avoid cycles from redundant re-export initialization - #11073
Conversation
✅ Deploy Preview for rolldown-rs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
Cross-chunk initialization routing is correctness-critical and has broad interactions despite the focused regression coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Prevents redundant re-export initialization from creating static chunk cycles while preserving consumer-selected leaf initialization.
Changes:
- Applies re-export transparency consistently across initialization routing.
- Adds regression coverage for strict wrapping and common-chunk inlining.
- Documents the initialization invariant and updates snapshots.
| File | Description |
|---|---|
internal-docs/code-splitting/implementation.md |
Documents transparent-wrapper initialization. |
transparent_plain_reexport_entry/shared-equality.js |
Adds forwarded leaf fixture. |
transparent_plain_reexport_entry/main.js |
Adds transparent entry fixture. |
transparent_plain_reexport_entry/artifacts.snap |
Captures entry output. |
transparent_plain_reexport_entry/_test.mjs |
Verifies exported behavior. |
transparent_plain_reexport_entry/_config.json |
Configures strict variants. |
transparent_plain_reexport_chunk_cycle/utilities/index.js |
Adds mixed forwarder fixture. |
transparent_plain_reexport_chunk_cycle/utilities-page.js |
Adds second consumer entry. |
transparent_plain_reexport_chunk_cycle/toast.js |
Consumes both exports. |
transparent_plain_reexport_chunk_cycle/shared-equality.js |
Adds forwarded implementation. |
transparent_plain_reexport_chunk_cycle/main.js |
Adds primary entry. |
transparent_plain_reexport_chunk_cycle/artifacts.snap |
Captures cycle-free outputs. |
transparent_plain_reexport_chunk_cycle/_test.mjs |
Checks cycles and runtime behavior. |
transparent_plain_reexport_chunk_cycle/_config.json |
Covers wrapping and inlining variants. |
emergent_cycle_partial_forwarder/artifacts.snap |
Removes redundant initializer edge. |
emergent_cycle_eager_reexport_overlay/artifacts.snap |
Removes redundant initializer edge. |
compute_wrapped_esm_init_metadata.rs |
Omits transparent-wrapper metadata obligations. |
esm_init_obligations.rs |
Uses the shared transparency predicate. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Merging this PR will not alter performance
Comparing Footnotes
|
@rolldown/browser
@rolldown/debug
rolldown
@rolldown/binding-android-arm-eabi
@rolldown/binding-android-arm64
@rolldown/binding-darwin-arm64
@rolldown/binding-darwin-x64
@rolldown/binding-freebsd-x64
@rolldown/binding-linux-arm-gnueabihf
@rolldown/binding-linux-arm64-gnu
@rolldown/binding-linux-arm64-musl
@rolldown/binding-linux-ppc64-gnu
@rolldown/binding-linux-s390x-gnu
@rolldown/binding-linux-x64-gnu
@rolldown/binding-linux-x64-musl
@rolldown/binding-openharmony-arm64
@rolldown/binding-wasm32-wasi
@rolldown/binding-win32-arm64-msvc
@rolldown/binding-win32-x64-msvc
commit: |
Merge activity
|
…tion (#11073) Enabling `experimentalInlineCommonChunks` can introduce a static cycle between output chunks even when the source modules have none. This PR removes the redundant import that creates the cycle, allowing the reproduction's bundle-cycle check to pass and eligible common chunks to be inlined. With the reproduction's `maxSize: 128`, the emitted imports are as follows, excluding the runtime chunk. Before: ```text app.js -> main.js main.js -> utilities.js utilities.js -> main.js utility-page.js -> utilities.js ``` After: ```text app.js -> utilities.js utility-page.js -> utilities.js ``` In the first output, `app.js` only initializes the application code in `main.js`. Removing the back-import allows that code to stay in `app.js`. The generated JavaScript runs successfully; the failure is the cycle check after bundling. With `maxSize: 4096`, the cycle also blocks inlining; the fix inlines the shared utilities into both entries. The cycle comes from `strictExecutionOrder`, which `experimentalInlineCommonChunks` enables. Its default wrap-all mode defers module execution through generated initialization functions. The shared utilities module only re-exports a binding and declares a function that uses none of its imports, so its consumers already initialize the defining modules for the bindings they read. Its own unused initializer also contains those calls, introducing an import back to the application chunk. The fix leaves these forwarding modules' initializers empty and keeps the required initialization at each consumer. It covers both retained and tree-shaken import statements. Chunk placement still follows the forwarding module's import records, which are needed to assign CommonJS dependencies behind re-export barrels to a chunk. Consumers follow the same rule when such a forwarding module also has `export *` from a side-effect-free external module. This fixes a related path that calls an empty initializer and then reads an uninitialized binding. Reading a name supplied only by the external module still requires namespace initialization. Modules with their own executable initialization retain their wrappers and may still form chunk cycles. Reproduction: [oriSomething/vite-inline-common-chunks-cycle-repro](oriSomething/vite-inline-common-chunks-cycle-repro@0466c4d)
60c28c0 to
794bf09
Compare
## [1.2.13] - 2026-10-07 ### 🚀 Features - rolldown_plugin_vite_import_glob: follow file creation and deletion via hotUpdate (#10550) by @shulaoda - inline-common-chunks: deduplicate shared code along known loading paths (#11093) by @hyfdev - rolldown_plugin_vite_import_glob: record a matcher per glob call in dev (#10592) by @shulaoda - rolldown_plugin_vite_import_glob: watch the directory each glob reads (#10549) by @shulaoda - watch: hand watch.exclude to notify as its ignore filter (#11008) by @shulaoda - dev: add `experimental.devMode.hotUpdate` option (#11123) by @h-a-n-a ### 🐛 Bug Fixes - renamer: check the printed name of namespace-alias imports for captures (#11129) by @IWANABETHATGUY - devtools: honor `devtools.sessionId` by @Brooooooklyn - renamer: keep a renamed nested binding off its module's top-level bindings (#11128) by @IWANABETHATGUY - dev: keep `this` undefined when calling an imported function in HMR patches and lazy chunks (#11126) by @h-a-n-a - dev: read string-named imports correctly in HMR patches and lazy chunks (#11127) by @h-a-n-a - sanitize preserveModules chunk names after resolving the relative path (#11087) by @waltuov - keep the `with` clause on bare external imports (#11100) by @IWANABETHATGUY - generator: filter DISABLE_JS_HOOK bits from generated HookUsage (#10346) by @Brooooooklyn - dev: make the module factory async for top-level await (#11118) by @h-a-n-a - node: give each renderChunk call its own meta object (#11115) by @Brooooooklyn - honor `externalLiveBindings` for imported exports (#11048) by @camc314 - dev: keep a late payload from replacing newer module code (#11030) by @h-a-n-a - binding: use-after-free in async `transform` with a `TsconfigCache` (#11080) by @shulaoda - fail on chunk syntax errors and escape export names once (#11051) by @hyfdev - dev: ship newly imported modules the client never received (#11029) by @h-a-n-a - code-splitting: avoid cycles from redundant re-export initialization (#11073) by @hyfdev - link: treat re-exports of the same external binding as one export (#11069) by @IWANABETHATGUY - escape namespace properties in IIFE and UMD output (#11085) by @hyfdev - escape dependency paths in CJS and UMD output (#11084) by @hyfdev - use computed access for arbitrary import names (#11083) by @hyfdev - generate valid bindings for shimmed exports (#11082) by @hyfdev - dev: reload the page when an HMR update fails after merging its edit (#11031) by @h-a-n-a - dev/lazy: ship the deps of a module that a patch shipped but never ran (#11028) by @h-a-n-a - code-splitting: don't move init calls in front of unwrapped JSON modules (#11062) by @IWANABETHATGUY - escape export names in `defineProperty` calls (#11047) by @camc314 ### 📚 Documentation - say the CLI bundles multiple configs one after another (#11111) by @Brooooooklyn - add `renderChunk` hook filter docs (#11065) by @sapphi-red ### ⚡ Performance - use `concat_string!` instead of `format!` for plain string joins (#11139) by @IWANABETHATGUY - utils: evaluate each `concat_string!` argument once (#11105) by @IWANABETHATGUY - json: escape `JSON.parse` string with `json-escape-simd` (#11104) by @IWANABETHATGUY - unwrap JSON modules with a non-object root (#11066) by @IWANABETHATGUY ### 🧪 Testing - inline-common-chunks: fix flaky inlineCommonChunks concurrent imports (#11088) by @hyfdev ### ⚙️ Miscellaneous Tasks - deps: upgrade oxc to 0.153.0 (#11109) by @camc314 - update pnpm to v12 (#10876) by @btea - deps: update pnpm to v11.28.0 (#11049) by @renovate[bot] - deps: update rollup submodule for tests to v4.64.0 (#11116) by @rolldown-guard[bot] - deps: update napi (#11137) by @renovate[bot] - scripts: spawn the rolldown CLI without a shell in setup-vite (#10875) by @Brooooooklyn - deps: bump `@napi-rs/wasm-runtime` to `~1.2.5` (#11117) by @shulaoda - deps: update napi (#11108) by @renovate[bot] - deps: update taiki-e/install-action action to v2.87.22 (#11096) by @renovate[bot] - deps: update npm packages (#11095) by @renovate[bot] - deps: update rust crates (#11097) by @renovate[bot] - deps: update napi (#11063) by @renovate[bot] - deps: update dependency rust to v1.99.0 (#11071) by @renovate[bot] - deps: update dependency vite-plus to v1 (#11056) by @renovate[bot] Co-authored-by: shulaoda <[email protected]>
Enabling
experimentalInlineCommonChunkscan introduce a static cycle between output chunks even when the source modules have none. This PR removes the redundant import that creates the cycle, allowing the reproduction's bundle-cycle check to pass and eligible common chunks to be inlined.With the reproduction's
maxSize: 128, the emitted imports are as follows, excluding the runtime chunk.Before:
After:
In the first output,
app.jsonly initializes the application code inmain.js. Removing the back-import allows that code to stay inapp.js. The generated JavaScript runs successfully; the failure is the cycle check after bundling. WithmaxSize: 4096, the cycle also blocks inlining; the fix inlines the shared utilities into both entries.The cycle comes from
strictExecutionOrder, whichexperimentalInlineCommonChunksenables. Its default wrap-all mode defers module execution through generated initialization functions. The shared utilities module only re-exports a binding and declares a function that uses none of its imports, so its consumers already initialize the defining modules for the bindings they read. Its own unused initializer also contains those calls, introducing an import back to the application chunk.The fix leaves these forwarding modules' initializers empty and keeps the required initialization at each consumer. It covers both retained and tree-shaken import statements. Chunk placement still follows the forwarding module's import records, which are needed to assign CommonJS dependencies behind re-export barrels to a chunk.
Consumers follow the same rule when such a forwarding module also has
export *from a side-effect-free external module. This fixes a related path that calls an empty initializer and then reads an uninitialized binding. Reading a name supplied only by the external module still requires namespace initialization.Modules with their own executable initialization retain their wrappers and may still form chunk cycles.
Reproduction: oriSomething/vite-inline-common-chunks-cycle-repro