Skip to content

Commit 802c20d

Browse files
refactor(client): no overlay code left to adapt
`client-src/overlay.js` was the last of it: an adapter whose substance was turning webpack's error objects into the shape the shared overlay renders, and a `send({ type })` state machine over `showProblems`/`clear`. Both belong elsewhere. The formatting is webpack-dev-middleware's `client/problem` now, and the state machine was standing in for per-source slots that overlay already has, so the events map onto two calls. What stays is this package's identity on top of a shared overlay, as options: the `webpack-dev-server-client-overlay` element id, so anything querying it is unaffected; the `webpack-dev-server#overlay` Trusted Types policy name, which a page's CSP allowlists by name; and the `/webpack-dev-server/open-editor` route that makes a file reference clickable. `test/client/ReactErrorBoundary.test.js` goes with it — the heuristic it covers lives in webpack-dev-middleware, which tests it. Requires webpack/webpack-dev-middleware#2438. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UjuMAuk9o6UazjHzcAQCTA
1 parent 883384a commit 802c20d

5 files changed

Lines changed: 49 additions & 456 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
"webpack-dev-server": patch
3+
---
4+
5+
The error overlay is webpack-dev-middleware's, with no code left here to adapt
6+
it. `client-src/overlay.js` is gone: the client calls
7+
`showProblems`/`clear` directly, since that overlay keeps a slot per reporting
8+
source and the state machine this package had was what stood in for that, and
9+
`formatProblem` comes from there too. What stays is this package's own
10+
identity on top of it — the `webpack-dev-server-client-overlay` element id,
11+
the `webpack-dev-server#overlay` Trusted Types policy name, and the
12+
`/webpack-dev-server/open-editor` route — passed as options.
13+
14+
Nothing changes for `client.overlay`, its `errors`/`warnings`/`runtimeErrors`
15+
filters, or `trustedTypesPolicyName`.

‎client-src/index.js‎

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
import hotEmitter from "webpack/hot/emitter.js";
44
// @ts-expect-error
55
import webpackHotLog from "webpack/hot/log.js";
6-
import { createOverlay, formatProblem } from "./overlay.js";
6+
import configureOverlay, {
7+
clear as clearOverlay,
8+
formatProblem,
9+
showProblems,
10+
} from "webpack-dev-middleware/client/overlay";
711
import { defineProgressElement, isProgressSupported } from "./progress.js";
812
import socket from "./socket.js";
913
import { log, setLogLevel } from "./utils/log.js";
@@ -313,20 +317,28 @@ self.addEventListener("pageshow", () => {
313317
status.isUnloading = false;
314318
});
315319

316-
const overlay =
317-
typeof window !== "undefined"
318-
? createOverlay(
319-
typeof options.overlay === "object"
320-
? {
321-
trustedTypesPolicyName: options.overlay.trustedTypesPolicyName,
322-
catchRuntimeError: options.overlay.runtimeErrors,
323-
}
324-
: {
325-
trustedTypesPolicyName: false,
326-
catchRuntimeError: options.overlay,
327-
},
328-
)
329-
: { send: () => {} };
320+
// The overlay is webpack-dev-middleware's. What stays here is this package's
321+
// own identity on top of it: the element id anything querying the overlay
322+
// knows, the Trusted Types policy name a page's CSP allowlists, and the route
323+
// this package serves for opening a file in an editor.
324+
if (typeof window !== "undefined") {
325+
configureOverlay({
326+
id: "webpack-dev-server-client-overlay",
327+
openEditorEndpoint: "/webpack-dev-server/open-editor",
328+
trustedTypesPolicyName:
329+
(typeof options.overlay === "object" &&
330+
options.overlay.trustedTypesPolicyName) ||
331+
"webpack-dev-server#overlay",
332+
catchRuntimeError:
333+
typeof options.overlay === "object"
334+
? options.overlay.runtimeErrors
335+
: options.overlay,
336+
});
337+
}
338+
339+
// Build problems live under one source, so a clean build drops them without
340+
// touching runtime errors — those are the overlay's own slot.
341+
const BUILD_PROBLEMS = "";
330342

331343
/**
332344
* @param {Options} options options
@@ -454,7 +466,7 @@ const onSocketMessage = {
454466
// A rebuild replaces the code a runtime error came from too, so unlike
455467
// `ok`/`still-ok` this clears that overlay as well.
456468
if (options.overlay) {
457-
overlay.send({ type: "DISMISS" });
469+
clearOverlay();
458470
}
459471

460472
sendMessage("Invalid");
@@ -523,7 +535,7 @@ const onSocketMessage = {
523535
log.info("Nothing changed.");
524536

525537
if (options.overlay) {
526-
overlay.send({ type: "BUILD_OK" });
538+
clearOverlay(BUILD_PROBLEMS);
527539
}
528540

529541
sendMessage("StillOk");
@@ -532,7 +544,7 @@ const onSocketMessage = {
532544
sendMessage("Ok");
533545

534546
if (options.overlay) {
535-
overlay.send({ type: "BUILD_OK" });
547+
clearOverlay(BUILD_PROBLEMS);
536548
}
537549

538550
reloadApp(options, status);
@@ -579,13 +591,7 @@ const onSocketMessage = {
579591
? warnings.filter(overlayWarningsSetting)
580592
: warnings;
581593

582-
if (warningsToDisplay.length) {
583-
overlay.send({
584-
type: "BUILD_ERROR",
585-
level: "warning",
586-
messages: warningsToDisplay,
587-
});
588-
}
594+
showProblems("warnings", warningsToDisplay, BUILD_PROBLEMS);
589595
}
590596

591597
if (params && params.preventReloading) {
@@ -623,13 +629,7 @@ const onSocketMessage = {
623629
? errors.filter(overlayErrorsSettings)
624630
: errors;
625631

626-
if (errorsToDisplay.length) {
627-
overlay.send({
628-
type: "BUILD_ERROR",
629-
level: "error",
630-
messages: errorsToDisplay,
631-
});
632-
}
632+
showProblems("errors", errorsToDisplay, BUILD_PROBLEMS);
633633
}
634634
},
635635
/**
@@ -642,7 +642,7 @@ const onSocketMessage = {
642642
log.info("Disconnected!");
643643

644644
if (options.overlay) {
645-
overlay.send({ type: "DISMISS" });
645+
clearOverlay();
646646
}
647647

648648
sendMessage("Close");

‎client-src/overlay.js‎

Lines changed: 0 additions & 177 deletions
This file was deleted.

‎eslint.config.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default defineConfig([
5757
files: [
5858
"client-src/clients/EventSourceClient.js",
5959
"client-src/clients/WebSocketClient.js",
60-
"client-src/overlay.js",
60+
"client-src/index.js",
6161
],
6262
rules: {
6363
"import/no-unresolved": "off",

0 commit comments

Comments
 (0)