Skip to content

fix(strict-execution-order): avoid eager loading through mixed re-exports - #11151

Merged
hyfdev merged 4 commits into
mainfrom
fix/11145-mixed-reexport-init
Oct 12, 2026
Merged

hyfdev merged 4 commits into
mainfrom
fix/11145-mixed-reexport-init

Conversation

@hyfdev

@hyfdev hyfdev commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

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.

// shared.js
export * from './values.js'; // export const LAZY = 'lazy';
export const LOCAL = 'local';

// main.js
import { LOCAL } from './shared.js';
export const load = () => import('./lazy.js');

// lazy.js
import { LAZY } from './shared.js';

Before:

// shared chunk
import { init_values } from './lazy.js';
function init_shared() {
  init_values();
  LOCAL = 'local';
}

After:

// shared chunk
function init_shared() {
  LOCAL = 'local';
}

// lazy chunk
function init_lazy() {
  init_values();
  init_shared();
}

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.

@netlify

netlify Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit d31468e
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/6acc7dc698a6ce0008e5a4f7

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://fix-11145-mixed-reexport-init-rolldown-rs.voidzero-docs.workers.dev (commit d31468e)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://8c429ec8-rolldown-rs.voidzero-docs.workers.dev d31468e 2026-10-12T06:29:36.214Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://e13a49c2-rolldown-rs.voidzero-docs.workers.dev c56e914 2026-10-12T02:42:22.293Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://3f2a6fd0-rolldown-rs.voidzero-docs.workers.dev c8f7313 2026-10-11T02:51:10.059Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://2dcb7150-rolldown-rs.voidzero-docs.workers.dev f09d749 2026-10-08T08:46:12.126Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://12c8c2f6-rolldown-rs.voidzero-docs.workers.dev 3531d25 2026-10-08T01:59:22.502Z Visit the dashboard ↗

@hyfdev hyfdev changed the title fix: avoid eager loading through mixed re-exports fix(strict-execution-order): avoid eager loading through mixed re-exports Oct 8, 2026
@hyfdev
hyfdev marked this pull request as ready for review October 8, 2026 05:09
Copilot AI balanced review requested due to automatic review settings October 8, 2026 05:09
@codspeed

codspeed Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ 4 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 7 untouched benchmarks
⏩ 10 skipped benchmarks1


Comparing fix/11145-mixed-reexport-init (d31468e) with main (bcaec87)

Open in CodSpeed

Footnotes

  1. 10 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 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.

@IWANABETHATGUY

Copy link
Copy Markdown
Member

With strictExecutionOrder: true and default wrapping, this star re-export chain exposes VALUE as undefined through Object.entries(ns). The parent commit f7de35f45 returns 'leaf' for VALUE; PR head f09d7498b omits init_leaf().

// 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';

@hyfdev

hyfdev commented Oct 11, 2026 •

Copy link
Copy Markdown
Member Author

With strictExecutionOrder: true and default wrapping, this star re-export chain exposes VALUE as undefined through Object.entries(ns). The parent commit f7de35f45 returns 'leaf' for VALUE; PR head f09d7498b omits init_leaf().

// 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)

@IWANABETHATGUY

Copy link
Copy Markdown
Member

The original reproduction passes now. These tests import ./main.js, so their assertions check source files:

  • crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_namespace/deep/_test.mjs
  • crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_namespace/lazy/_test.mjs
  • crates/rolldown/tests/rolldown/function/experimental/strict_execution_order/mixed_reexport_namespace/visibility/_test.mjs

All configured variants also pass when these tests import ./dist/main.js and use node:assert/strict.

@hyfdev
hyfdev force-pushed the fix/11145-mixed-reexport-init branch from c8f7313 to c56e914 Compare October 12, 2026 02:40
@hyfdev
hyfdev removed this pull request from stack #11163 October 12, 2026 06:07
@hyfdev
hyfdev added this pull request to stack #11187 October 12, 2026 06:07
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.
@hyfdev
hyfdev force-pushed the fix/11145-mixed-reexport-init branch from c56e914 to d31468e Compare October 12, 2026 06:27
@hyfdev
hyfdev merged commit 3f219e0 into main Oct 12, 2026
37 checks passed
@hyfdev
hyfdev deleted the fix/11145-mixed-reexport-init branch October 12, 2026 06:39
hyfdev added a commit that referenced this pull request Oct 12, 2026
…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>
@rolldown-guard rolldown-guard Bot mentioned this pull request Oct 14, 2026
shulaoda added a commit that referenced this pull request Oct 14, 2026
## [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]>
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.

[Feature Request]: avoid eager loading through mixed re-exports with strictExecutionOrder

3 participants