fix(vite): replace the browser preload helper before esbuild minifies it - #11425
Merged
NathanWalker merged 1 commit intoSep 10, 2026
Conversation
|
View your CI Pipeline Execution ↗ for commit 7d8ead3
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗ ☁️ Nx Cloud last updated this comment at |
commit: |
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.
PR Checklist
What is the current behavior?
dynamicImportPluginreplaces Vite's browser__vitePreloadhelper (which touchesdocumentandwindow) with a native one, but it does so fromgenerateBundleusing a literal regex on the identifier. Withbuild.minify: 'esbuild'Vite'svite:esbuild-transpileplugin has already renamed__vitePreloadinrenderChunk, so the regex misses, the browser helper ships, and itswindow.dispatchEventin the rejection path turns every failed dynamic import intoReferenceError: window is not definedwith a misattributed stack. Details in #11423.What is the new behavior?
The transform runs in
renderChunkas anenforce: 'post'plugin. User post plugins run beforebuildPlugins.post(where the esbuild minifier lives), so the helper is still named when it is replaced.renderChunkreturnsnullwhen nothing changed, so untouched chunks and already-transformed code are left alone.transformDynamicImportsis unchanged.Specs cover the plugin shape (post + renderChunk, no generateBundle), the replacement through
renderChunk, and the no-op/idempotent return.Verified with a real
ns build iosof a blank Vue app withbuild.minify: 'esbuild': the emitted bundle contains the native helper and novite:preloadError/document.createElement("link"); the published 8.0.5 bundle has the reverse. At runtime a deliberately failingimport()now reports the real load error.Fixes #11423.