-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrefresh-hack.js
31 lines (26 loc) · 996 Bytes
/
refresh-hack.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// eslint-disable-next-line
import { injectIntoGlobalHook } from "/@react-refresh";
injectIntoGlobalHook(window);
const globalHook = window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
const oldCommit = globalHook.onCommitFiberRoot;
globalHook.onCommitFiberRoot = function (
id,
root,
maybePriorityLevel,
didError
) {
try {
if (!root.containerInfo.dataset.hacked) {
// In SSR context, the root is considered mounted and waiting for hydration.
// Old commit function from react-refresh would not track this root, thus,
// disable vite hot reload. We clears the element to work around that.
root.current.alternate.memoizedState.element = null;
// remember this root node, as if we keep reseting, react-dev-tools won't
// be able to work properly.
root.containerInfo.dataset.hacked = true;
}
} catch (ignored) {}
oldCommit(id, root, maybePriorityLevel, didError);
};
window.$RefreshReg$ = () => {};
window.$RefreshSig$ = () => (type) => type;