Repository navigation
fix(rolldown_plugin_vite_build_import_analysis): only wrap dynamic imports with static specifiers in __vitePreload - #10879
Conversation
Merging this PR will not alter performance
|
|
I think we should skip wrapping with If we were to wrap, we have to keep the sideeffect outside of the let _temp = await resolveSpecifier(spec)
return await __vitePreload(() => import(_temp), []);. Generating this is a bit tricky. |
A dynamic import whose argument contains an `await` is wrapped as
__vitePreload(() => import(await resolveUrl()), [...])
The thunk is a *synchronous* arrow, so the `await` is stranded in a
non-async scope and the emitted chunk fails to parse:
SyntaxError: Unexpected identifier. import call expects one or two
arguments
Emit `async () => ...` instead. This is validity-preserving for every
argument expression and inert for the common string/identifier case,
since __vitePreload invokes and awaits the thunk immediately. The
destructuring path (construct_vite_preload_call) already builds an async
arrow; this brings the two remaining paths in line.
Not a pre-existing Vite behaviour: Vite 7, which ran this transform in
JS on Rollup, left dynamic imports with non-analyzable specifiers
unwrapped, so nothing could be stranded. Rolldown wraps them too, which
is what surfaces the bug.
The same fix shape was applied to vitest browser modes equivalent thunk
in vitest-dev/vitest#10784.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The awaited specifier is computed at runtime, so rolldown never emits lib.js as a chunk and the dynamic import cannot resolve when the built module is executed. Export the loaders instead of invoking them: simply importing dist/main.js is the assertion, since a synchronous preload thunk makes that module a syntax error. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
59a948d to
92b8d23
Compare
…static specifier Match Vite 7: wrap `import()` in `__vitePreload` only when its specifier is a string or template literal. A computed specifier such as `import(await resolveSpecifier())` gives nothing to preload, and wrapping it in the synchronous thunk left the `await` outside an async scope. Replaces the earlier change that made the thunk `async`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
92b8d23 to
012dda2
Compare
|
Hi @sapphi-red @IWANABETHATGUY I have gotten back to this issue. I have changed to skip wrapping with __vitePreload like v7. |
|
Thanks! |
## [1.2.15] - 2026-10-21 ### 🚀 Features - rolldown_plugin_vite_resolve: add `isBundled` to pick the browser-external stub format (#11260) by @h-a-n-a - dev: mark entry modules in the HMR module graph (#11252) by @h-a-n-a - mark module starts with `// <id>` comments instead of `#region` pairs (#11235) by @IWANABETHATGUY ### 🐛 Bug Fixes - plugin: stop `this.resolve` recursion between plugins with `skipSelf: true` (#11181) by @anzal1 - rolldown_plugin_vite_resolve: handle external `require` for `ssr.target: 'webworker'` (#11205) by @sapphi-red - rolldown_plugin_vite_build_import_analysis: only wrap dynamic imports with static specifiers in __vitePreload (#10879) by @smeng9 - strict-execution-order: wrap eager modules that forward wrapped definers (#11186) by @hyfdev - chunk-import-map: keep common chunk keys unique when enabling inline common chunks (#11230) by @hyfdev - only register signal-exit handler when a trace subscriber is active (#11208) by @DaniilIsupov ### 🧪 Testing - fold hand-unrolled Rust test tables (#11212) by @Brooooooklyn ### ⚙️ Miscellaneous Tasks - deps: upgrade oxc to 0.155.0 (#11228) by @Dunqing - rollup-tests: retriage failed tests (#11251) by @sapphi-red - deps: update rollup submodule for tests to v4.64.12 (#11249) by @rolldown-guard[bot] - deps: update test262 submodule for tests (#11242) by @rolldown-guard[bot] ### ❤️ New Contributors * @anzal1 made their first contribution in [#11181](#11181) * @smeng9 made their first contribution in [#10879](#10879) * @DaniilIsupov made their first contribution in [#11208](#11208) Co-authored-by: shulaoda <[email protected]>
Fixes downstream vitejs/vite#23485