Repository navigation
Conversation
…tejs#23221) Co-Authored-By: Claude <noreply@anthropic.com>
Member
|
fixed by #24028 and rolldown/rolldown#11157 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #23221: two mutually-exclusive
__vitePreloadcalls (conditional dynamic imports) get merged by minification into a single call whose first argument becomes a ternary, but whose second argument (the deps array) keeps only one branch's deps — silently dropping the other branch's preloaded assets (JS chunk preload + CSS).Root cause
The native
vite:build-import-analysisplugin wraps every bare dynamicimport()as:All markers are the identical string
__VITE_PRELOAD__. When two such calls sit in mutually-exclusive branches, the minifier folds them into one call:The first arg becomes a correct ternary, but the second arg is a side-effect-free array literal that the minifier keeps from only one branch. The other branch's CSS and JS-chunk preloads are silently dropped at runtime.
Fix
In
importAnalysisBuild.tsrenderChunk, uniquify each__VITE_PRELOAD__marker into__VITE_PRELOAD_<n>__before minification. Distinct marker strings make the two__vitePreload(...)calls non-mergeable, so each branch's deps array is preserved.Supporting changes:
preloadMarkerREnow matches both the plain and uniquified markers;matchImportsToPreloadMarkers/generateBundlemarker scanning and rewriting use the full marker span (preloadMarkerEnd).renderChunknow emits a real sourcemap (previouslymap: null) so async chunks that carry markers (e.g. nested dynamic imports) keep their.mapfiles.Testing
conditional dynamic imports keep both branches preload deps (#23221)inpackages/vite/src/node/__tests__/build.spec.ts, which asserts the preload deps registry contains both branches' JS + CSS (4 entries, 2 CSS).expected [ …(2) ] to have a length of 4 but got 2.pnpm vitest run packages/vite/src/node/__tests__/→ 44 files / 650 tests passed.oxfmtandeslintclean.Notes
The report is against vite 8.0.16; this root cause was independently reproduced on the repo's current
main(8.2.1 / rolldown 1.2.1) using the repo's ownbuild()with a virtual-module fixture. No changeset added — Vite generates its changelog from the PR title.Closes #23221