diff --git a/src/hooks/useHMR.ts b/src/hooks/useHMR.ts index ff54518..d541906 100644 --- a/src/hooks/useHMR.ts +++ b/src/hooks/useHMR.ts @@ -19,8 +19,14 @@ if ( (module as any).hot && typeof window !== 'undefined' ) { - const win = window as any; - if (typeof win.webpackHotUpdate === 'function') { + // Use `globalThis` first, and `window` for older browsers + // const win = globalThis as any; + const win = + typeof globalThis !== 'undefined' + ? globalThis + : ((typeof window !== 'undefined' ? window : null) as any); + + if (win && typeof win.webpackHotUpdate === 'function') { const originWebpackHotUpdate = win.webpackHotUpdate; win.webpackHotUpdate = (...args: any[]) => {