fix(plugin-react): use '/' base in bundledDev preamble to fix non-root base paths#1197
Open
JustInCache wants to merge 1 commit intovitejs:mainfrom
Open
fix(plugin-react): use '/' base in bundledDev preamble to fix non-root base paths#1197JustInCache wants to merge 1 commit intovitejs:mainfrom
JustInCache wants to merge 1 commit intovitejs:mainfrom
Conversation
Author
|
@hi-ogawa Can you please review ? Suggest feedback if any !! Thanks |
…t base paths In bundled dev mode (`experimental.bundledDev: true`), Rolldown resolves module specifiers at build time without any URL-level base stripping. Using `config.base` in `getPreambleCode` produced an import like `/@react-refresh` prefixed with the custom base (e.g. `/static/@react-refresh`), which Rolldown couldn't resolve since the `resolveId` hook only matches the exact string `/@react-refresh`. Fix by passing `'/'` instead of `config.base` to `getPreambleCode` in the `viteReactRefreshBundledDevMode` plugin, consistent with how `virtualPreamblePlugin` already handles this case. Fixes vitejs#1190 Made-with: Cursor
e8c8bbe to
d5a73d5
Compare
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.
Summary
Fixes #1190
When using
experimental: { bundledDev: true }with a non-rootbase(e.g.base: "/static/"), thevite:react-refresh-fbmplugin was callinggetPreambleCode(base), producing:Rolldown resolves module specifiers at build time — there is no URL-level base-stripping middleware involved. So
/static/@react-refreshnever matched theresolveIdhook which only handles the exact string/@react-refresh, causing:In non-bundled dev mode this worked because the browser fetched the URL and Vite's
baseMiddlewarestripped the prefix before the request reached the resolve/load hooks.Fix
Pass
'/'instead ofconfig.basetogetPreambleCodeinsideviteReactRefreshBundledDevMode. This produces/@react-refreshdirectly, which theresolveIdhook can match. This is consistent with whatvirtualPreamblePluginalready does (with the comment "vite dev import analysis can rewrite base").Test
Added a new e2e playground
playground/bundled-dev-base-pathwithbase: '/static/'+experimental: { bundledDev: true }that verifies:UNRESOLVED_IMPORTbrowser errors