Skip to content

fix(lazy-barrel): request all exports for entry barrels on first encounter#9672

Merged
shulaoda merged 2 commits into
mainfrom
06-09-fix_lazy-barrel_request_all_exports_for_entry_barrels_on_first_encounter
Jun 9, 2026
Merged

fix(lazy-barrel): request all exports for entry barrels on first encounter#9672
shulaoda merged 2 commits into
mainfrom
06-09-fix_lazy-barrel_request_all_exports_for_entry_barrels_on_first_encounter

Conversation

@shulaoda

@shulaoda shulaoda commented Jun 8, 2026

Copy link
Copy Markdown
Member

Background

Surfaced downstream as vitejs/vite#22593@emotion/react breaks under Vite's dependency pre-bundling once experimental.lazyBarrel is the default: @emotion/react imports withEmotionCache for local use and also re-exports it, and @emotion/styled imports only the re-export, producing ReferenceError: withEmotionCache$1 is not defined. The minimal repro below is that pattern reduced.

Repro

m.js        export function x(){...}  export function y(){...}
barrel.js   import { x } from './m'   // record#0: local use, in useX()
            export { y } from './m'   // a re-export
            export function useX(){ return x() }
consumer.js export { y } from './barrel'   // requests ONLY the re-export y
splitter.js export { y } from './m'        // makes m its own chunk

useX()ReferenceError: x is not defined.

Problem

barrel is a barrel and a user entry. consumer requests only its re-export y, so barrel is processed with Partial({ y })has_local_export is false → lazy barrel defers barrel's own import { x } record (resolved_module = None). But barrel is an entry, so its body is still emitted and uses x — which was never imported → dangling reference.

An entry must keep all its exports, so it should request All and load every record. That recovery existed but only in the Some(VisitState::Seen) branch; a first-time entry registration goes through the None branch and skips it. (Order-sensitive, hence intermittent — if an importer registered the module first, the entry add hit Seen and it worked.)

Flow

  1. barrel registered as entry (first encounter, None arm) → recovery skipped.
  2. consumer imports y → records Partial({ y }) on barrel.
  3. barrel initializes → take_needed_records(Partial({ y })), has_local_export = falseimport { x } record deferred, never resolved.
  4. binder skips the unresolved record → useX's x unbound → emitted barrel references an undefined x.

@netlify

netlify Bot commented Jun 8, 2026

Copy link
Copy Markdown

Deploy Preview for rolldown-rs canceled.

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

@shulaoda shulaoda force-pushed the 06-09-fix_lazy-barrel_request_all_exports_for_entry_barrels_on_first_encounter branch from 381c9f5 to 9df53ef Compare June 8, 2026 16:17
@codspeed-hq

codspeed-hq Bot commented Jun 8, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 4 untouched benchmarks
⏩ 10 skipped benchmarks1


Comparing 06-09-fix_lazy-barrel_request_all_exports_for_entry_barrels_on_first_encounter (b1b149f) with main (9ba6aeb)2

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.

  2. No successful run was found on main (77d6de7) during the generation of this report, so 9ba6aeb was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@pkg-pr-new

pkg-pr-new Bot commented Jun 8, 2026

Copy link
Copy Markdown

Open in StackBlitz

@rolldown/browser

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/browser@9672 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/browser@9672 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/browser@9672.tgz -D

@rolldown/debug

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/debug@9672 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/debug@9672 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/debug@9672.tgz -D

rolldown

pnpm add https://pkg.pr.new/rolldown/rolldown@9672 -D
npm i https://pkg.pr.new/rolldown/rolldown@9672 -D
yarn add https://pkg.pr.new/rolldown/rolldown@9672.tgz -D

@rolldown/binding-android-arm64

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-android-arm64@9672 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-android-arm64@9672 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-android-arm64@9672.tgz -D

@rolldown/binding-darwin-arm64

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-darwin-arm64@9672 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-darwin-arm64@9672 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-darwin-arm64@9672.tgz -D

@rolldown/binding-darwin-x64

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-darwin-x64@9672 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-darwin-x64@9672 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-darwin-x64@9672.tgz -D

@rolldown/binding-freebsd-x64

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-freebsd-x64@9672 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-freebsd-x64@9672 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-freebsd-x64@9672.tgz -D

@rolldown/binding-linux-arm-gnueabihf

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-arm-gnueabihf@9672 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-arm-gnueabihf@9672 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-arm-gnueabihf@9672.tgz -D

@rolldown/binding-linux-arm64-gnu

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-arm64-gnu@9672 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-arm64-gnu@9672 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-arm64-gnu@9672.tgz -D

@rolldown/binding-linux-arm64-musl

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-arm64-musl@9672 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-arm64-musl@9672 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-arm64-musl@9672.tgz -D

@rolldown/binding-linux-ppc64-gnu

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-ppc64-gnu@9672 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-ppc64-gnu@9672 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-ppc64-gnu@9672.tgz -D

@rolldown/binding-linux-s390x-gnu

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-s390x-gnu@9672 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-s390x-gnu@9672 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-s390x-gnu@9672.tgz -D

@rolldown/binding-linux-x64-gnu

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-x64-gnu@9672 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-x64-gnu@9672 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-x64-gnu@9672.tgz -D

@rolldown/binding-linux-x64-musl

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-x64-musl@9672 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-x64-musl@9672 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-x64-musl@9672.tgz -D

@rolldown/binding-openharmony-arm64

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-openharmony-arm64@9672 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-openharmony-arm64@9672 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-openharmony-arm64@9672.tgz -D

@rolldown/binding-wasm32-wasi

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-wasm32-wasi@9672 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-wasm32-wasi@9672 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-wasm32-wasi@9672.tgz -D

@rolldown/binding-win32-arm64-msvc

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-win32-arm64-msvc@9672 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-win32-arm64-msvc@9672 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-win32-arm64-msvc@9672.tgz -D

@rolldown/binding-win32-x64-msvc

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-win32-x64-msvc@9672 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-win32-x64-msvc@9672 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-win32-x64-msvc@9672.tgz -D

commit: 9df53ef

@shulaoda shulaoda merged commit 811b2f9 into main Jun 9, 2026
34 checks passed
@shulaoda shulaoda deleted the 06-09-fix_lazy-barrel_request_all_exports_for_entry_barrels_on_first_encounter branch June 9, 2026 08:49
@shulaoda shulaoda mentioned this pull request Jun 11, 2026
@rolldown-guard rolldown-guard Bot mentioned this pull request Jun 11, 2026
shulaoda pushed a commit that referenced this pull request Jun 11, 2026
## [1.1.1] - 2026-06-11

### 🚀 Features

- ecmascript_utils: introduce AstFactory for AST construction (#9682) by @hyf0
- drop no-op init calls for empty wrapped-ESM modules (#9678) by @IWANABETHATGUY

### 🐛 Bug Fixes

- resolver: honor package.json#type for .jsx/.tsx extensions (#9690) (#9699) by @IWANABETHATGUY
- hmr: report the full-reload reason for the invalidate-loop case (#9708) by @hyf0
- explicit `moduleSideEffects` from a hook must take priority over the `package.json#sideEffects` (#9688) by @sapphi-red
- keep the `rolldown-runtime` name for the standalone runtime chunk (#9685) by @shulaoda
- lazy-barrel: request all exports for entry barrels on first encounter (#9672) by @shulaoda
- finalizer: skip init_*() for tree-shaken wrapped ESM owners (#9669) by @IWANABETHATGUY
- order `chunk.imports` by execution order (#9654) by @chuganzy
- vite-resolve: preserve slash separators for Sass partial exports (#9546) by @cjc0013
- cross-chunk CJS wrapper shadowed by author-local binding (#9648) by @IWANABETHATGUY

### 🚜 Refactor

- precompute wrapped-ESM init metadata in generate stage (#9712) by @IWANABETHATGUY
- ecmascript_utils: fold construction ext traits onto AstFactory and delete AstSnippet (#9702) by @hyf0
- finalizer: finish ScopeHoistingFinalizer migration to AstFactory (#9701) by @hyf0
- finalizer: migrate module_finalizers/mod.rs to AstFactory (#9700) by @hyf0
- hmr: migrate hmr finalizer to AstFactory (#9695) by @hyf0
- plugin: migrate vite_build_import_analysis to AstFactory (#9693) by @hyf0
- scanner: migrate tweak_ast_for_scanning to AstFactory (#9683) by @hyf0
- always split runtime module first (#9419) by @IWANABETHATGUY

### 📚 Documentation

- tsconfig: correct auto-discovery resolution to match TypeScript (#9714) by @shulaoda
- design: plan to unify all internal AST construction (#9673) by @hyf0
- tsconfig: align reference resolution docs with TypeScript behavior (#9641) by @shulaoda

### ⚡ Performance

- avoid per-module join Strings in scope-hoisting concatenation (#9645) by @Boshen
- avoid intermediate Strings in the ESM export clause (#9644) by @Boshen
- reuse a scratch buffer for facade namespace names in the scanner (#9642) by @Boshen
- reuse the import-matching tracker stack across named imports (#9643) by @Boshen
- avoid cloning the per-chunk export-items map in render_chunk_exports (#9639) by @Boshen
- avoid CompactStr allocation in sorted-exports membership check (#9640) by @Boshen

### 🧪 Testing

- add more `moduleSideEffects` precedence tests (#9689) by @sapphi-red
- 9651: drop shimMissingExports from regression fixture (#9674) by @IWANABETHATGUY

### ⚙️ Miscellaneous Tasks

- update react repo links (#9711) by @iiio2
- remove outdated pnpm configurations (#9666) by @btea
- deps: update github actions to v2.81.5 (#9665) by @renovate[bot]
- testing: migrate test harness off deprecated inlineDynamicImports (#9710) by @IWANABETHATGUY
- hmr: delete commented-out dead code left from old register-module codegen (#9707) by @hyf0
- deps: update napi-rs toolchain (#9706) by @shulaoda
- deps: update rollup submodule for tests to v4.61.1 (#9676) by @rolldown-guard[bot]
- deps: update test262 submodule for tests (#9677) by @rolldown-guard[bot]
- deps: update oxc to 0.135.0 (#9670) by @Boshen
- pass ALGOLIA_APP_ID and ALGOLIA_API_KEY to void deploy (#9667) by @Boshen
- deps: update github actions (#9662) by @renovate[bot]
- deps: update rust crates (#9663) by @renovate[bot]
- deps: update rolldown-plugin-dts to v0.25.2 (#9661) by @renovate[bot]
- deps: update typos to v1.47.2 (#9660) by @renovate[bot]
- deps: update docs dependencies (#9657) by @bddjr
- deps: update typos to v1.47.1 (#9655) by @renovate[bot]
- deploy website in its own workflow, only on docs output change (#9650) by @Boshen
- publish to pkg.pr.new add pm and `commentWithDev` option (#9638) by @btea

### ❤️ New Contributors

* @chuganzy made their first contribution in [#9654](#9654)
* @cjc0013 made their first contribution in [#9546](#9546)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants