Skip to content

Commit 309991f

Browse files
fix: do not crush when error is null for runtime errors (#5447)
1 parent 70ba684 commit 309991f

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

client-src/overlay.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,10 +664,16 @@ const createOverlay = (options) => {
664664
if (!error && !message) {
665665
return;
666666
}
667+
667668
// if error stack indicates a React error boundary caught the error, do not show overlay.
668-
if (error.stack && error.stack.includes("invokeGuardedCallbackDev")) {
669+
if (
670+
error &&
671+
error.stack &&
672+
error.stack.includes("invokeGuardedCallbackDev")
673+
) {
669674
return;
670675
}
676+
671677
handleError(error, message);
672678
});
673679

test/client/clients/ReactErrorBoundary.test.js renamed to test/client/ReactErrorBoundary.test.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
"use strict";
66

7-
const { createOverlay } = require("../../../client-src/overlay");
7+
const { createOverlay } = require("../../client-src/overlay");
88

99
describe("createOverlay", () => {
1010
const originalDocument = global.document;
@@ -108,6 +108,29 @@ describe("createOverlay", () => {
108108
showOverlayMock.mockRestore();
109109
});
110110

111+
it("should show overlay for normal uncaught errors (when null is thrown)", () => {
112+
const options = { trustedTypesPolicyName: null, catchRuntimeError: true };
113+
const overlay = createOverlay(options);
114+
const showOverlayMock = jest.spyOn(overlay, "send");
115+
116+
const errorEvent = new ErrorEvent("error", {
117+
error: null,
118+
message: "error",
119+
});
120+
window.dispatchEvent(errorEvent);
121+
122+
expect(showOverlayMock).toHaveBeenCalledWith({
123+
type: "RUNTIME_ERROR",
124+
messages: [
125+
{
126+
message: "error",
127+
stack: expect.anything(),
128+
},
129+
],
130+
});
131+
showOverlayMock.mockRestore();
132+
});
133+
111134
it("should show overlay for normal uncaught errors when catchRuntimeError is a function that return true", () => {
112135
const options = {
113136
trustedTypesPolicyName: null,

0 commit comments

Comments
 (0)