Skip to content

Commit 9644f5e

Browse files
committed
cleanup
1 parent 1e2327f commit 9644f5e

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

packages/common/refresh-utils.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,27 +69,27 @@ function $RefreshSig$() { return RefreshRuntime.createSignatureFunctionForTransf
6969
}
7070

7171
export function virtualPreamblePlugin({
72-
name,
7372
isEnabled,
7473
}: {
75-
name: string
7674
isEnabled: () => boolean
7775
}): Plugin {
76+
const VIRTUAL_NAME = 'virtual:@vitejs/plugin-react/preamble'
7877
return {
7978
name: 'vite:react-virtual-preamble',
79+
apply: 'serve',
8080
resolveId: {
8181
order: 'pre',
82-
filter: { id: exactRegex(name) },
82+
filter: { id: exactRegex(VIRTUAL_NAME) },
8383
handler(source) {
84-
if (source === name) {
84+
if (source === VIRTUAL_NAME) {
8585
return '\0' + source
8686
}
8787
},
8888
},
8989
load: {
90-
filter: { id: exactRegex('\0' + name) },
90+
filter: { id: exactRegex('\0' + VIRTUAL_NAME) },
9191
handler(id) {
92-
if (id === '\0' + name) {
92+
if (id === '\0' + VIRTUAL_NAME) {
9393
if (isEnabled()) {
9494
// vite dev import analysis can rewrite base
9595
return preambleCode.replace('__BASE__', '/')
@@ -102,9 +102,10 @@ export function virtualPreamblePlugin({
102102
filter: { code: /__REACT_DEVTOOLS_GLOBAL_HOOK__/ },
103103
handler(code, _id, options) {
104104
if (options?.ssr) return
105+
105106
// this is expected to be either `react` or `react-dom/client`
106107
if (isEnabled() && code.includes('__REACT_DEVTOOLS_GLOBAL_HOOK__')) {
107-
return `import ${JSON.stringify(name)};` + code
108+
return `import ${JSON.stringify(VIRTUAL_NAME)};` + code
108109
}
109110
},
110111
},

packages/plugin-react/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,6 @@ export default function viteReact(opts: Options = {}): Plugin[] {
526526
: []),
527527
viteReactRefresh,
528528
virtualPreamblePlugin({
529-
name: '@vitejs/plugin-react/preamble',
530529
isEnabled: () => !skipFastRefresh && !isFullBundle,
531530
}),
532531
]

0 commit comments

Comments
 (0)