Skip to content

Commit 91cfd01

Browse files
committed
fix(client): prevent overlay from closing immediately on runtime error at initial load
1 parent b550a70 commit 91cfd01

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

client-src/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,15 @@ const decodeOverlayOptions = (overlayOptions) => {
8484
const status = {
8585
isUnloading: false,
8686
currentHash: __webpack_hash__,
87+
hasRuntimeError: false,
8788
};
89+
window.addEventListener("error", () => {
90+
status.hasRuntimeError = true;
91+
});
8892

93+
window.addEventListener("unhandledrejection", () => {
94+
status.hasRuntimeError = true;
95+
});
8996
/**
9097
* @returns {string} current script source
9198
*/
@@ -403,8 +410,7 @@ const onSocketMessage = {
403410
invalid() {
404411
log.info("App updated. Recompiling...");
405412

406-
// Fixes #1042. overlay doesn't clear if errors are fixed but warnings remain.
407-
if (options.overlay) {
413+
if (options.overlay && !status.hasRuntimeError) {
408414
overlay.send({ type: "DISMISS" });
409415
}
410416

@@ -473,7 +479,7 @@ const onSocketMessage = {
473479
"still-ok": function stillOk() {
474480
log.info("Nothing changed.");
475481

476-
if (options.overlay) {
482+
if (options.overlay && !status.hasRuntimeError) {
477483
overlay.send({ type: "DISMISS" });
478484
}
479485

@@ -482,6 +488,8 @@ const onSocketMessage = {
482488
ok() {
483489
sendMessage("Ok");
484490

491+
status.hasRuntimeError = false;
492+
485493
if (options.overlay) {
486494
overlay.send({ type: "DISMISS" });
487495
}

0 commit comments

Comments
 (0)