Repository navigation
fix(strict-execution-order): avoid eager loading through mixed re-exports - #11151
Conversation
✅ Deploy Preview for rolldown-rs canceled.
|
Merging this PR will not alter performance
|
There was a problem hiding this comment.
🔵 Needs a closer look
Cross-phase initialization ownership changes need human validation, particularly for unwrapped mixed forwarders in on-demand mode.
2 open findings
What changed in this PR
Extends Rolldown’s strict-execution-order routing to keep pure lazy re-exports out of startup’s static imports, addressing #11145.
Changes:
- Routes eligible re-export initialization through consumers while preserving required dependencies.
- Updates chunk placement, initialization metadata, and entry activation.
- Adds regression coverage and documents routing safeguards.
| File | Description |
|---|---|
| internal-docs/code-splitting/implementation.md | Documents per-record routing. |
| internal-docs/code-splitting/design.md | Explains eligibility and ordering safeguards. |
| crates/rolldown/tests/rolldown/issues/11145/values.js | Defines the lazy value. |
| crates/rolldown/tests/rolldown/issues/11145/shared.js | Reproduces mixed exports. |
| crates/rolldown/tests/rolldown/issues/11145/main.js | Exercises startup and lazy loading. |
| crates/rolldown/tests/rolldown/issues/11145/lazy.js | Consumes the forwarded value. |
| crates/rolldown/tests/rolldown/issues/11145/artifacts.snap | Records separated chunk output. |
| crates/rolldown/tests/rolldown/issues/11145/_test.mjs | Checks exported values. |
| crates/rolldown/tests/rolldown/issues/11145/_config.json | Configures regression variants. |
| crates/rolldown/tests/rolldown/function/strict_execution_order_invariants/mod.rs | Checks static-import isolation. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_sensitive/state.js | Supplies mutable state. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_sensitive/snapshots/value.js | Captures the imported state. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_sensitive/snapshots/package.json | Declares side-effect-free snapshots. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_sensitive/snapshots/forwarder.js | Adds a transitive forwarding hop. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_sensitive/shared.js | Mixes sensitive and pure exports. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_sensitive/pure.js | Supplies an eligible pure export. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_sensitive/main.js | Mutates state before lazy loading. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_sensitive/lazy.js | Reads snapshot and pure values. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_sensitive/artifacts.snap | Records snapshot initialization order. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_sensitive/_test.mjs | Verifies snapshot timing. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_sensitive/_config.json | Configures optimization variants. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_records/shared.js | Combines forwarding and required dependencies. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_records/required.js | Supplies a required side effect. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_records/nested.js | Exercises nested re-exports. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_records/main.js | Loads two independent consumers. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_records/lazy-b.js | Exercises namespace-member access. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_records/lazy-a.js | Exercises named-import access. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_records/b.js | Defines the second lazy value. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_records/artifacts.snap | Records independent lazy chunks. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_records/a.js | Defines the first lazy value. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_records/_test.mjs | Checks ordering and object identity. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_records/_config.json | Adds wrapping and output variants. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_entry/value.js | Supplies an entry export. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_entry/shared.js | Defines a mixed dynamic entry. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_entry/main.js | Exercises entry export initialization. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_entry/forwarded.js | Supplies a dynamic-entry value. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_entry/artifacts.snap | Records entry initialization output. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_entry/_test.mjs | Checks entry values and identity. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_entry/_config.json | Configures entry regression variants. |
| crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/cross_chunk_dynamic_importer_uses_call_site_trigger/artifacts.snap | Updates call-site initialization output. |
| crates/rolldown/src/stages/generate_stage/order_wrapping.rs | Selects and applies per-record routes. |
| crates/rolldown/src/stages/generate_stage/order_wrap_state.rs | Stores routed-record state. |
| crates/rolldown/src/stages/generate_stage/order_analysis.rs | Supplies runtime context to probes. |
| crates/rolldown/src/stages/generate_stage/compute_wrapped_esm_init_metadata.rs | Excludes consumer-owned initialization records. |
| crates/rolldown/src/stages/generate_stage/code_splitting.rs | Accounts for mixed-module routes. |
| crates/rolldown/src/esm_init_obligations.rs | Resolves consumer-owned initialization targets. |
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
3531d25 to
f09d749
Compare
|
With // main.js
import * as ns from './outer.js';
export const entries = Object.entries(ns);
// outer.js
export * from './mixed.js';
// mixed.js
export * from './leaf.js';
export const LOCAL = 'local';
// leaf.js
export const VALUE = 'leaf'; |
Fixed in #11151 (this PR) |
|
The original reproduction passes now. These tests import
All configured variants also pass when these tests import |
c8f7313 to
c56e914
Compare
An unwrapped mixed module has no startup initialization site for a non-routed re-export whose definer is order-wrapped and has no binding consumer at startup, so on-demand wrapping evaluates that definer later than wrap-all. The design and implementation notes describe the gap, and `mixed_reexport_sensitive` pins it with expected-failure variants.
c56e914 to
d31468e
Compare
…itting (#11162) With `strictExecutionOrder: true`, a startup entry can statically import a lazy chunk because that chunk hosts a module whose `init_*` the entry must call. Chunk placement now counts those `init_*` calls as loading edges, so the module lands beside its callers and the lazy code stays lazy. ```js // main.js import { cn } from 'pure-barrel'; export const loadRoute = () => import('./route.js'); // node_modules/pure-barrel/index.js (sideEffects: false) export * from './extra.cjs'; export { cn } from './cn.js'; export { default as cloneDeep } from './clone-deep.cjs'; // route.js import { cloneDeep, extraValue } from 'pure-barrel'; ``` Before, `main.js` imports `init_pure_barrel` from the `route.js` chunk. After, the barrel sits beside `main.js` and the `route.js` chunk holds only route code. Tree shaking resolves `cn` to `cn.js`, so the barrel gets only the route's entry bits. Main must still call the barrel's `init_*` (its CommonJS `export *` keeps the barrel monolithic), and that cross-chunk import is registered only after placement. Under on-demand wrapping the pass follows the wrap-all plan, so an unwrapped pure mixed module can be pulled into a chunk shared by consumers that would call its wrapper under wrap-all. Stacked on #11151. --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
## [1.2.14] - 2026-10-14 ### 🚀 Features - add `output.charset` option (#11194) by @sapphi-red - code-splitting: route independent ESM re-exports per consumer (#11177) by @hyfdev ### 🐛 Bug Fixes - handle `output.charset: 'ascii'` + `output.minify: false` (#11207) by @sapphi-red - tree-shaking: preserve initialization of wrapped ESM re-exports (#11167) by @hyfdev - sourcemap: preserve boundaries when tracing has no mapping (#11170) by @sapphi-red - strict-execution-order: account for init imports during code splitting (#11162) by @hyfdev - strict-execution-order: avoid eager loading through mixed re-exports (#11151) by @hyfdev - tree-shake expression statements that coerce known constants (#10825) by @IWANABETHATGUY - shim-missing-exports: shim deep namespace reads through default imports (#11184) by @IWANABETHATGUY - shim-missing-exports: shim missing static namespace members (#11179) by @hyfdev - preserve-entry-signatures: keep internal bindings out of entry exports (#11094) by @hyfdev - report ASSIGN_TO_IMPORT for writes to re-exported namespace members (#11148) by @IWANABETHATGUY - dev: keep files loaded by the HMR stage watched when the same task rebuilds (#11154) by @Brooooooklyn - dev: watch lazily compiled files even when a build starts first (#11152) by @Brooooooklyn - cjs: print a CommonJS module's top-level `this` as a wrapper parameter rolldown names (#11135) by @IWANABETHATGUY - renamer: keep fixed names off the bindings that would capture them (#11134) by @IWANABETHATGUY - renamer: keep an external `require()` local in a CJS module off the top-level names (#11133) by @IWANABETHATGUY - rolldown: make a repeated `close()` a no-op (#11142) by @Brooooooklyn - avoid renaming entry top-level bindings onto their nested bindings (#11122) by @IWANABETHATGUY - renamer: keep generated top-level names off inner bindings (#11121) by @IWANABETHATGUY ### 🚜 Refactor - renamer: treat a CJS-wrapped module's root scope as an inner scope (#11130) by @IWANABETHATGUY ### 📚 Documentation - add renaming design and implementation docs (#11131) by @IWANABETHATGUY ### ⚡ Performance - ci: overlap independent setup, checks, and artifacts (#11169) by @hyfdev ### 🧪 Testing - dev: use dunce::canonicalize so dev engine tests pass on Windows (#11192) by @shulaoda - preserve-entry-signatures: cover nested dynamic imports (#11164) by @hyfdev ### ⚙️ Miscellaneous Tasks - deps: upgrade oxc to 0.154.0 (#11209) by @shulaoda - make Security Analysis pass again (security-action v1.0.10, serde_yaml -> saphyr) (#11197) by @Brooooooklyn - deps: update rollup submodule for tests to v4.64.5 (#11190) by @rolldown-guard[bot] - deps: update test262 submodule for tests (#11191) by @rolldown-guard[bot] - deps: update crate-ci/typos action to v1.51.1 (#11174) by @renovate[bot] - vite-tests: link the workspace rolldown into the Vite clone again (#11147) by @Brooooooklyn Co-authored-by: shulaoda <[email protected]>


With
strictExecutionOrder: true, importing a local export from a module that also re-exports pure values pulls the lazy chunk hosting those values into startup. Initialization of such re-exports now belongs to the consumer that imports them, so startup loads only what it uses.Before:
After:
A re-export record is routed to its consumers when the target and its static dependency closure have no side effects and nothing execution-order sensitive; otherwise the mixed module's wrapper keeps initializing it. Namespace consumers initialize the forwarded bindings their record exposes;
default, shadowed and ambiguous names are excluded.In CommonJS output, a chunk's re-export of a wrapper imported from another chunk renders through the
require()result (mixed_reexport_dynamic_entry).Not covered: under on-demand wrapping, an unwrapped mixed module gives a forwarded order-sensitive definer no startup initialization site when no startup consumer imports it (#10294,
mixed_reexport_sensitive).Fixes #11145.