Skip to content

Commit c5b000f

Browse files
authored
fix(plugin-swc): skip HMR preamble in Vitest browser mode (#478)
1 parent 7517103 commit c5b000f

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

packages/plugin-react-swc/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Skip HMR preamble in Vitest browser mode
6+
7+
This was causing annoying `Sourcemap for "/@react-refresh" points to missing source files` and is unnecessary in test mode.
8+
59
## 3.9.0 (2025-04-15)
610

711
### Make compatible with rolldown-vite

packages/plugin-react-swc/src/index.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,17 @@ const react = (_options?: Options): PluginOption[] => {
132132
)
133133
}
134134
},
135-
transformIndexHtml: (_, config) => [
136-
{
137-
tag: 'script',
138-
attrs: { type: 'module' },
139-
children: getPreambleCode(config.server!.config.base),
140-
},
141-
],
135+
transformIndexHtml: (_, config) => {
136+
if (!hmrDisabled) {
137+
return [
138+
{
139+
tag: 'script',
140+
attrs: { type: 'module' },
141+
children: getPreambleCode(config.server!.config.base),
142+
},
143+
]
144+
}
145+
},
142146
async transform(code, _id, transformOptions) {
143147
const id = _id.split('?')[0]
144148
const refresh = !transformOptions?.ssr && !hmrDisabled

0 commit comments

Comments
 (0)