Skip to content

Commit

Permalink
use globalThis instead of window in HMR (#134)
Browse files Browse the repository at this point in the history
* use globalThis instead of window in HMR

* Update src/hooks/useHMR.ts

Co-authored-by: antoniopresto <[email protected]>

* chore: adjust logic

---------

Co-authored-by: antoniopresto <[email protected]>
Co-authored-by: 二货机器人 <[email protected]>
  • Loading branch information
3 people authored Nov 11, 2024
1 parent eabc24e commit 10c7642
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/hooks/useHMR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) => {
Expand Down

0 comments on commit 10c7642

Please sign in to comment.