fix(plugin-react-swc): support bundledDev mode (fix #1271)#1279
Open
AmariahAK wants to merge 1 commit into
Open
fix(plugin-react-swc): support bundledDev mode (fix #1271)#1279AmariahAK wants to merge 1 commit into
AmariahAK wants to merge 1 commit into
Conversation
In bundledDev mode, config.server is undefined, causing
transformIndexHtml to crash when accessing config.server.config.base.
Detect bundledDev in configResolved and use getPreambleCode('/')
instead, matching the fix already applied in plugin-react (6c57dd4).
Add bundled-dev test playground to verify the server starts without
the config.server crash.
Co-authored-by: atlarix-agent <agent@atlarix.dev>
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
TypeError: Cannot read properties of undefined (reading 'config')
at PluginContextImpl.transformIndexHtml (…/@vitejs/plugin-react-swc/index.js:137:46)
How it was fixed
Detected
bundledDevmode inconfigResolvedviaconfig.experimental.bundledDev, and branched thetransformIndexHtmlhandler to usegetPreambleCode('/')(hardcoded/base) when in bundledDev mode. In bundled dev, assets are served as static files and don't go through the dev server middlewares, so the configured base prefix isn't needed.This follows the exact same pattern already implemented in
@vitejs/plugin-react(commit 6c57dd4).Why this method
The alternative of trying to extract the base from another config source would be fragile and inconsistent. The reference implementation in
plugin-reactalready solved this correctly by using'/'in bundledDev — bundling produces static assets at predictable paths that don't need URL rewriting.How to test
Changes
packages/plugin-react-swc/src/index.ts— detectbundledDevinconfigResolved, branchtransformIndexHtmlto usegetPreambleCode('/')when active (+16/-2 lines)packages/plugin-react-swc/playground/bundled-dev/— new test playground verifying the server starts without error (7 files)pnpm-lock.yaml— updated for the new playgroundAll 22 existing tests continue to pass; the new bundled-dev test passes.