fix(overlay): keep a runtime error raised during the initial load - #5745
Conversation
An error thrown while the entry is still evaluating raises the overlay before the client's socket handshake completes. The compilation itself succeeded, so the handshake's `ok` arrived milliseconds later and sent `DISMISS`, closing an overlay it knew nothing about. `ok` and `still-ok` now send `BUILD_OK`, which only the build-error state handles. `invalid` keeps sending `DISMISS`: a rebuild replaces the code a runtime error came from, so that overlay is stale too. Closes #5024
🦋 Changeset detectedLatest commit: f40996e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. WalkthroughThe client now sends Priority: ➖ Normal 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning Some tools did not complete. Review the errors below. 🔧 ESLint
test/client/index.test.jsESLint failed to execute (timeout). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5745 +/- ##
==========================================
+ Coverage 90.29% 90.83% +0.54%
==========================================
Files 13 13
Lines 6241 6282 +41
==========================================
+ Hits 5635 5706 +71
+ Misses 606 576 -30 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
Closes #5024. An error thrown while the entry is still evaluating raises the overlay before the client's socket handshake completes; the compilation itself succeeded, so the handshake's
okarrived milliseconds later and sentDISMISS, closing an overlay it knew nothing about (measured: error at +50ms, overlay at +67ms,okat +73ms, overlay gone at +74ms — andreloadAppthen returns early on itsisInitialguard, so nothing puts it back).okandstill-oknow send a newBUILD_OKevent that only the build-error state handles.invalidkeeps sendingDISMISS, because a rebuild replaces the code a runtime error came from — so editing the file still clears a runtime overlay exactly as it does today, rather than leaving a stale one after an HMR update that does not reload the page.What kind of change does this PR introduce?
fix
Did you add tests for your changes?
Yes.
test/e2e/overlay.test.jsgains "should keep the overlay for a runtime error thrown during the initial load", driven by a new fixture (test/fixtures/overlay-config/throw-on-initial-load.js) that throws during entry evaluation — the existing runtime-error tests inject viaaddScriptTagafternetworkidle0, which is the already-working path and is why nothing caught this. Verified against a client built from unmodifiedclient-src: it fails withexpect(received).not.toBeNull() / Received: null, and passes after rebuilding with the fix.test/client/overlay-lifecycle.test.jsadds a state-machine case pinning thatBUILD_OKclears a build error but not a runtime one, andtest/client/index.test.jsis updated where it pinned the oldstill-okbehaviour.Does this PR introduce a breaking change?
No.
If relevant, what needs to be documented once your changes are merged or what have you already documented?
n/a — the overlay's documented behaviour is unchanged; this only stops it closing an error it was meant to show.
Use of AI
AI-assisted (Claude Code). It was used to reproduce the issue in a browser — instrumenting
WebSocketand aMutationObserverto get the causal ordering above — and to draft the fix and the tests. Every claim here was verified by running it: the regression test was confirmed to fail on an unmodified client and pass with the fix, the full overlay suite (39/39) andtest/client/**pass, andnpm run lintexits 0. All output was reviewed before committing.🤖 Generated with Claude Code
https://claude.ai/code/session_01UjuMAuk9o6UazjHzcAQCTA
Generated by Claude Code
Summary by CodeRabbit
Bug Fixes
Tests