Fix blank ErrorBoundary when multiple exceptions thrown in one batch - #69342
Open
dariatiurina wants to merge 3 commits into
Open
dariatiurina wants to merge 3 commits into
dariatiurina wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Two moderate findings remain, along with a minor test-name nit.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Fixes blank ErrorBoundary output when multiple child components throw in one render batch.
Changes:
- Coalesces pending subtree-clear renders per error boundary.
- Adds unit and end-to-end regression coverage.
- Updates test helpers for repeated exception notifications.
File summaries
| File | Summary | Findings |
|---|---|---|
src/Components/Components/src/RenderTree/Renderer.cs |
Tracks pending boundary subtree clears. | Moderate (1 vote): Delayed exceptions after disposal can leave tracking IDs in the renderer. |
src/Components/Components/test/ComponentBaseTest.cs |
Adds same-batch exception coverage. | Moderate (2 votes): Assertions do not verify the boundary’s error content or render output. |
src/Components/test/E2ETest/Tests/ErrorBoundaryTest.cs |
Adds end-to-end regression coverage. | Nit (2 votes): Rename ForOnce to CanHandleMultipleExceptionsAtOnce. |
src/Components/test/testassets/BasicTestApp/ErrorBoundaryTest/ForeachErrorsChild.razor |
Adds a throwing child component fixture. | No findings. |
src/Components/test/testassets/BasicTestApp/ErrorBoundaryTest/ErrorBoundaryCases.razor |
Adds the foreach error scenario. | No findings. |
src/Components/Components/test/RendererTest.cs |
Allows repeated exception notifications. | No findings. |
Review details
Suppressed comments (1)
src/Components/Components/src/RenderTree/Renderer.cs:1216
- When a delayed exception is routed to a boundary after disposal,
AddToRenderQueuereturns because the state is no longer registered. Since thisAddhappens first, the disposal cleanup has already run and cannot remove the newly-added ID; each such boundary leaves an entry in the HashSet for the renderer lifetime. Guard the tracking add with a registered-state check (or makeAddToRenderQueuereport whether it enqueued).
if (_errorBoundariesWithPendingSubtreeClear.Add(boundaryComponentId))
- Files reviewed: 6/6 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+467
to
+469
| // Assert | ||
| Assert.NotNull(capturedBoundary); | ||
| Assert.NotNull(capturedBoundary.ReceivedException); |
| } | ||
|
|
||
| [Fact] | ||
| public void CanHandleMultipleExceptionsForOnce() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes
ErrorBoundaryrendering when multiple child components throw during the same render batch. The renderer now preserves the boundary's error content instead of leaving the boundary blank.Changes
The first forced empty render remains ahead of the boundary's error-content render, so the failed subtree is discarded. Suppressing duplicate empty renders prevents a later one from clearing the error content.
Testing
@foreach, verifying that the error UI is displayed without triggering the global error state.Fixes #56950