Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions client-src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import sendMessage from "./utils/sendMessage.js";
* @property {boolean} isUnloading true when unloaded, otherwise false
* @property {string} currentHash current hash
* @property {string=} previousHash previous hash
* @property {boolean} hasRuntimeError true when a runtime error occurred
*/

/**
Expand Down Expand Up @@ -84,8 +85,15 @@ const decodeOverlayOptions = (overlayOptions) => {
const status = {
isUnloading: false,
currentHash: __webpack_hash__,
hasRuntimeError: false,
};
window.addEventListener("error", () => {
status.hasRuntimeError = true;
});

window.addEventListener("unhandledrejection", () => {
status.hasRuntimeError = true;
});
Copy link
Copy Markdown
Member

@alexander-akait alexander-akait Mar 12, 2026

Choose a reason for hiding this comment

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

This code can be run in web workers and it will broken

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for pointing this out. I’ve updated it to use self instead of window so it works correctly in web workers as well. Please take another look.

/**
* @returns {string} current script source
*/
Expand Down Expand Up @@ -403,8 +411,7 @@ const onSocketMessage = {
invalid() {
log.info("App updated. Recompiling...");

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

Expand Down Expand Up @@ -473,7 +480,7 @@ const onSocketMessage = {
"still-ok": function stillOk() {
log.info("Nothing changed.");

if (options.overlay) {
if (options.overlay && !status.hasRuntimeError) {
overlay.send({ type: "DISMISS" });
}

Expand All @@ -482,6 +489,8 @@ const onSocketMessage = {
ok() {
sendMessage("Ok");

status.hasRuntimeError = false;

if (options.overlay) {
overlay.send({ type: "DISMISS" });
}
Expand Down
49 changes: 49 additions & 0 deletions test/e2e/overlay-initial-runtime-error.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"use strict";

const path = require("node:path");
const puppeteer = require("puppeteer");
const webpack = require("webpack");
const WebpackDevServer = require("../../lib/Server");

describe("overlay runtime error", () => {
let browser;
let page;
let server;

beforeAll(async () => {
const config = {
mode: "development",
entry: path.resolve(__dirname, "../fixtures/overlay-runtime-error.js"),
};

const compiler = webpack(config);

server = new WebpackDevServer(
{
port: 8081,
client: {
overlay: true,
},
},
compiler,
);

await server.start();

browser = await puppeteer.launch();
page = await browser.newPage();
});

afterAll(async () => {
await browser.close();
await server.stop();
});

it("should keep overlay visible on runtime error during initial load", async () => {
await page.goto("http://localhost:8081");

const overlay = await page.$("webpack-dev-server-client-overlay");

expect(overlay).not.toBeNull();
});
});
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please use e2e overlay existing tests

Copy link
Copy Markdown
Author

@kehach07 kehach07 Mar 10, 2026

Choose a reason for hiding this comment

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

Thanks for the suggestion. I moved the test into the existing overlay e2e tests.
It reproduces the runtime error on initial load and verifies that the overlay stays visible.
Let me know if anything else should be adjusted.

1 change: 1 addition & 0 deletions test/fixtures/overlay-runtime-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
throw new Error("Initial runtime error");