Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: catch runtime error #4605

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 22 additions & 13 deletions client-src/index.js
Expand Up @@ -4,7 +4,7 @@ import webpackHotLog from "webpack/hot/log.js";
import stripAnsi from "./utils/stripAnsi.js";
import parseURL from "./utils/parseURL.js";
import socket from "./socket.js";
import { formatProblem, show, hide } from "./overlay.js";
import { formatProblem, createOverlay } from "./overlay.js";
import { log, logEnabledFeatures, setLogLevel } from "./utils/log.js";
import sendMessage from "./utils/sendMessage.js";
import reloadApp from "./utils/reloadApp.js";
Expand Down Expand Up @@ -115,6 +115,13 @@ self.addEventListener("beforeunload", () => {
status.isUnloading = true;
});

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

const overlay = createOverlay({
trustedTypesPolicyName,
});

const onSocketMessage = {
hot() {
if (parsedResourceQuery.hot === "false") {
Expand All @@ -135,7 +142,7 @@ const onSocketMessage = {

// Fixes #1042. overlay doesn't clear if errors are fixed but warnings remain.
if (options.overlay) {
hide();
overlay.send({ type: "DISMISS" });
}

sendMessage("Invalid");
Expand Down Expand Up @@ -192,7 +199,7 @@ const onSocketMessage = {
log.info("Nothing changed.");

if (options.overlay) {
hide();
overlay.send({ type: "DISMISS" });
}

sendMessage("StillOk");
Expand All @@ -201,7 +208,7 @@ const onSocketMessage = {
sendMessage("Ok");

if (options.overlay) {
hide();
overlay.send({ type: "DISMISS" });
}

reloadApp(options, status);
Expand Down Expand Up @@ -256,10 +263,11 @@ const onSocketMessage = {
: options.overlay && options.overlay.warnings;

if (needShowOverlayForWarnings) {
const trustedTypesPolicyName =
typeof options.overlay === "object" &&
options.overlay.trustedTypesPolicyName;
show("warning", warnings, trustedTypesPolicyName || null);
overlay.send({
type: "BUILD_ERROR",
level: "warning",
messages: warnings,
});
}

if (params && params.preventReloading) {
Expand Down Expand Up @@ -292,10 +300,11 @@ const onSocketMessage = {
: options.overlay && options.overlay.errors;

if (needShowOverlayForErrors) {
const trustedTypesPolicyName =
typeof options.overlay === "object" &&
options.overlay.trustedTypesPolicyName;
show("error", errors, trustedTypesPolicyName || null);
overlay.send({
type: "BUILD_ERROR",
level: "error",
messages: errors,
});
}
},
/**
Expand All @@ -308,7 +317,7 @@ const onSocketMessage = {
log.info("Disconnected!");

if (options.overlay) {
hide();
overlay.send({ type: "DISMISS" });
}

sendMessage("Close");
Expand Down