Skip to content
Merged
26 changes: 19 additions & 7 deletions client-src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import createSocketURL from "./utils/createSocketURL.js";
* @property {boolean} hot
* @property {boolean} liveReload
* @property {boolean} progress
* @property {boolean | { warnings?: boolean, errors?: boolean, trustedTypesPolicyName?: string }} overlay
* @property {boolean | { warnings?: boolean, errors?: boolean, runtimeErrors?: boolean, trustedTypesPolicyName?: string }} overlay
* @property {string} [logging]
* @property {number} [reconnect]
*/
Expand Down Expand Up @@ -80,6 +80,7 @@ if (parsedResourceQuery.overlay) {
options.overlay = {
errors: true,
warnings: true,
runtimeErrors: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default it to true.

...options.overlay,
};
}
Expand Down Expand Up @@ -115,12 +116,23 @@ self.addEventListener("beforeunload", () => {
status.isUnloading = true;
});

const trustedTypesPolicyName =
typeof options.overlay === "object" && options.overlay.trustedTypesPolicyName;

const overlay = createOverlay({
trustedTypesPolicyName,
});
const overlay = options.overlay

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@malcolm-kee this is not sufficient. You are only checking if options.overlay is truthy. All options need to be passed into the createOverlay() function. The overlay options are errors: boolean & warnings: boolean.

Then, the show() function in overlay.js needs to check if the type is "warning" or "error" and compare the passed options.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crobinson42 good catch!

I just pushed a fix so that runtime error check the options as well.

For build error/warning, it's already handled:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testa are failed, can you look what is wrong (no rush), I think today after rest we will fix all issues

? createOverlay(
typeof options.overlay === "object"
? {
trustedTypesPolicyName: options.overlay.trustedTypesPolicyName,
catchRuntimeError: options.overlay.runtimeErrors,
}
: {
trustedTypesPolicyName: false,
catchRuntimeError: options.overlay,
}
)
: {
send() {
// noop
},
};

const onSocketMessage = {
hot() {
Expand Down
37 changes: 20 additions & 17 deletions client-src/overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ function formatProblem(type, item) {
/**
* @typedef {Object} CreateOverlayOptions
* @property {string | null} trustedTypesPolicyName
* @property {boolean} [catchRuntimeError]
*/

/**
Expand Down Expand Up @@ -271,24 +272,26 @@ const createOverlay = (options) => {
hideOverlay: hide,
});

listenToRuntimeError((errorEvent) => {
// error property may be empty in older browser like IE
const { error, message } = errorEvent;
if (!error && !message) {
return;
}
const errorObject =
error instanceof Error ? error : new Error(error || message);
overlayService.send({
type: "RUNTIME_ERROR",
messages: [
{
message: errorObject.message,
stack: parseErrorToStacks(errorObject),
},
],
if (options.catchRuntimeError && typeof window !== "undefined") {
listenToRuntimeError((errorEvent) => {
// error property may be empty in older browser like IE
const { error, message } = errorEvent;
if (!error && !message) {
return;
}
const errorObject =
error instanceof Error ? error : new Error(error || message);
overlayService.send({
type: "RUNTIME_ERROR",
messages: [
{
message: errorObject.message,
stack: parseErrorToStacks(errorObject),
},
],
});
});
});
}

return overlayService;
};
Expand Down
2 changes: 1 addition & 1 deletion lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ const schema = require("./options.json");
/**
* @typedef {Object} ClientConfiguration
* @property {"log" | "info" | "warn" | "error" | "none" | "verbose"} [logging]
* @property {boolean | { warnings?: boolean, errors?: boolean }} [overlay]
* @property {boolean | { warnings?: boolean, errors?: boolean, runtimeErrors?: boolean }} [overlay]
* @property {boolean} [progress]
* @property {boolean | number} [reconnect]
* @property {"ws" | "sockjs" | string} [webSocketTransport]
Expand Down
Loading