mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 02:54:11 +08:00
fix(webpack): prevent hmr from patching __onLiveSync multiple times (#10103)
This commit is contained in:
@ -6,6 +6,8 @@
|
||||
if (module.hot) {
|
||||
let hash = __webpack_require__.h();
|
||||
let hmrBootEmittedSymbol = Symbol.for('HMRBootEmitted');
|
||||
let originalLiveSyncSymbol = Symbol.for('OriginalLiveSync');
|
||||
let hmrRuntimeLastLiveSyncSymbol = Symbol.for('HMRRuntimeLastLiveSync');
|
||||
|
||||
const logVerbose = (title: string, ...info: any) => {
|
||||
if (__NS_ENV_VERBOSE__) {
|
||||
@ -108,8 +110,12 @@ if (module.hot) {
|
||||
].some((path) => requireExists(path));
|
||||
};
|
||||
|
||||
const originalOnLiveSync = global.__onLiveSync;
|
||||
global.__onLiveSync = async function () {
|
||||
if (global.__onLiveSync !== global[hmrRuntimeLastLiveSyncSymbol]) {
|
||||
// we store the original liveSync here in case this code runs again
|
||||
// which happens when you module.hot.accept() the main file
|
||||
global[originalLiveSyncSymbol] = global.__onLiveSync;
|
||||
}
|
||||
global[hmrRuntimeLastLiveSyncSymbol] = async function () {
|
||||
logVerbose('LiveSync');
|
||||
|
||||
if (!hasUpdate()) {
|
||||
@ -120,9 +126,10 @@ if (module.hot) {
|
||||
return false;
|
||||
}
|
||||
|
||||
await originalOnLiveSync();
|
||||
await global[originalLiveSyncSymbol]();
|
||||
};
|
||||
|
||||
global.__onLiveSync = global[hmrRuntimeLastLiveSyncSymbol];
|
||||
if (!global[hmrBootEmittedSymbol]) {
|
||||
global[hmrBootEmittedSymbol] = true;
|
||||
setStatus(hash, 'boot', 'HMR Enabled - waiting for changes...');
|
||||
|
Reference in New Issue
Block a user