Skip to content

Commit 37a99f2

Browse files
committed
feat(client): share the overlay across bundled copies and report by source (#2368)
* feat(client): share the overlay across bundled copies and report by source The overlay DOM and problem state now live in a window singleton, so a second bundled copy of the module (e.g. the webpack-dev-server client once it adopts this overlay) renders into the same iframe instead of stacking a duplicate. Fields missing from a state created by an older copy are filled in place, and the Trusted Types policy moves into the shared state too — creating two policies with the same name throws under an enforced CSP. * test(overlay): prevent re-rendering when clearing a source that reported nothing
1 parent 672da3c commit 37a99f2

12 files changed

Lines changed: 561 additions & 83 deletions

File tree

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,19 @@ overlay.showProblems("errors", ["Something broke"]);
449449
overlay.clear();
450450
```
451451

452+
The overlay state is a per-page singleton: every bundled copy of the module
453+
renders into the same overlay. Multiple clients can report side by side by
454+
passing a `source` — each source keeps its own slot and the overlay shows the
455+
union, with errors from any source taking precedence over warnings:
456+
457+
```js
458+
overlay.showProblems("errors", ["Something broke"], "my-client");
459+
// Drop only this client's problems; other sources stay on screen.
460+
overlay.clear("my-client");
461+
// Without a source, everything is dismissed (same as Esc / backdrop / ×).
462+
overlay.clear();
463+
```
464+
452465
The building indicator is exposed the same way:
453466

454467
```js

client-src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,10 @@ function createReporter() {
356356
return false;
357357
}
358358

359-
overlay.clear();
359+
// Clear only this client's problems and the runtime errors — other
360+
// clients sharing the overlay keep theirs.
361+
overlay.clear("");
362+
overlay.clear("runtime");
360363
return true;
361364
};
362365

0 commit comments

Comments
 (0)