fix(react-swc): fix @vitejs/plugin-react-swc/preamble on build#962
Merged
hi-ogawa merged 3 commits intovitejs:mainfrom Nov 5, 2025
Merged
fix(react-swc): fix @vitejs/plugin-react-swc/preamble on build#962hi-ogawa merged 3 commits intovitejs:mainfrom
@vitejs/plugin-react-swc/preamble on build#962hi-ogawa merged 3 commits intovitejs:mainfrom
Conversation
Add dedicated plugin to ensure hmrDisabled is set to true for all build configurations, preventing React refresh runtime from being included in production bundles. Otherwise: ```✗ Build failed in 20ms error during build: [vite]: Rollup failed to resolve import "/@react-refresh" from "@vitejs/plugin-react-swc/preamble". This is most likely unintended because it can break your application at runtime. If you do want to externalize this module explicitly add it to `build.rollupOptions.external` ```
hi-ogawa
reviewed
Nov 4, 2025
Contributor
There was a problem hiding this comment.
I think this is a bug fix? Probably I missed that hmrDisabled = true happens with apply: 'serve' currently
vite-plugin-react/packages/plugin-react-swc/src/index.ts
Lines 119 to 136 in 99d0fc4
I think it should be safe to flip the logic by starting from let hmrDisabled = true and then check config.server.hmr !== false, which becomes closer to @vitejs/plugin-react
Member
|
Yeah I would prefer to avoid an extra plugin which makes thinks harder to track |
Contributor
Author
|
Have updated the implementation |
@vitejs/plugin-react-swc/preamble on build
ArnaudBarre
approved these changes
Nov 5, 2025
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.
Description
Should ensure hmrDisabled is set to true during build, preventing React refresh runtime from being included in production bundles.
Otherwise: