@@ -28,10 +28,12 @@ window.$RefreshSig$ = () => (type) => type
2828window.__vite_plugin_react_preamble_installed__ = true
2929`
3030
31- const header = `
31+ const sharedHeader = `
3232import RefreshRuntime from "${ runtimePublicPath } ";
3333
3434const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
35+ ` . replace ( / \n + / g, '' )
36+ const functionHeader = `
3537let prevRefreshReg;
3638let prevRefreshSig;
3739
@@ -51,11 +53,13 @@ if (import.meta.hot && !inWebWorker) {
5153 window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
5254}` . replace ( / \n + / g, '' )
5355
54- const footer = `
56+ const functionFooter = `
5557if (import.meta.hot && !inWebWorker) {
5658 window.$RefreshReg$ = prevRefreshReg;
5759 window.$RefreshSig$ = prevRefreshSig;
58-
60+ }`
61+ const sharedFooter = `
62+ if (import.meta.hot && !inWebWorker) {
5963 RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
6064 RefreshRuntime.registerExportsForReactRefresh(__SOURCE__, currentExports);
6165 import.meta.hot.accept((nextExports) => {
@@ -68,8 +72,19 @@ if (import.meta.hot && !inWebWorker) {
6872
6973export function addRefreshWrapper ( code : string , id : string ) : string {
7074 return (
71- header . replace ( '__SOURCE__' , JSON . stringify ( id ) ) +
75+ sharedHeader +
76+ functionHeader . replace ( '__SOURCE__' , JSON . stringify ( id ) ) +
7277 code +
73- footer . replace ( '__SOURCE__' , JSON . stringify ( id ) )
78+ functionFooter +
79+ sharedFooter . replace ( '__SOURCE__' , JSON . stringify ( id ) )
80+ )
81+ }
82+
83+ export function addClassComponentRefreshWrapper (
84+ code : string ,
85+ id : string ,
86+ ) : string {
87+ return (
88+ sharedHeader + code + sharedFooter . replace ( '__SOURCE__' , JSON . stringify ( id ) )
7489 )
7590}
0 commit comments