Skip to content

Commit c0233a2

Browse files
committed
Recover from HMR fails
1 parent a263ad8 commit c0233a2

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

packages/app/src/sandbox/eval/transpiled-module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,7 @@ export default class TranspiledModule {
867867
if (typeof path === 'undefined') {
868868
this.hmrConfig = this.hmrConfig || new HMR();
869869
this.hmrConfig.setType('decline');
870+
this.resetCompilation();
870871
} else {
871872
const paths = typeof path === 'string' ? [path] : path;
872873

@@ -877,6 +878,7 @@ export default class TranspiledModule {
877878
);
878879
tModule.hmrConfig = tModule.hmrConfig || new HMR();
879880
tModule.hmrConfig.setType('decline');
881+
tModule.resetCompilation();
880882
});
881883
}
882884
manager.enableWebpackHMR();

packages/app/src/sandbox/eval/transpilers/react/refresh-transpiler.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ function debounce(func, wait, immediate) {
2121
};
2222
};
2323
24-
const enqueueUpdate = debounce(Refresh.performReactRefresh, 30);
24+
const enqueueUpdate = () => {
25+
try {
26+
Refresh.performReactRefresh()
27+
} catch (e) {
28+
module.hot.decline();
29+
throw e;
30+
}
31+
}
2532
2633
function isReactRefreshBoundary(moduleExports) {
2734
if (Object.keys(Refresh).length === 0) {
@@ -56,7 +63,7 @@ function isReactRefreshBoundary(moduleExports) {
5663
};
5764
5865
module.exports = {
59-
enqueueUpdate,
66+
enqueueUpdate: debounce(enqueueUpdate, 30),
6067
isReactRefreshBoundary
6168
};
6269
`.trim();

0 commit comments

Comments
 (0)