-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Fixed the ErrorBoundary multiple errors bug #63254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed the ErrorBoundary multiple errors bug #63254
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request fixes a bug in Blazor's ErrorBoundary handling where multiple simultaneous errors could cause issues. The fix prevents unnecessary state updates when component initialization tasks are faulted, improving error boundary behavior.
Key changes:
- Modified
ComponentBase
to skipStateHasChanged()
calls when initialization tasks are faulted - Added comprehensive test coverage for error boundary scenarios with multiple errors
- Created test components to simulate and verify error boundary behavior with faulted tasks
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
src/Components/Components/src/ComponentBase.cs | Added condition to prevent StateHasChanged when initialization task is faulted |
src/Components/Components/test/ComponentBaseTest.cs | Added unit test and helper components for error boundary testing |
src/Components/test/testassets/BasicTestApp/ErrorBoundaryTest/MultipleErrorsChild.razor | New test component that throws errors in both OnInitializedAsync and BuildRenderTree |
src/Components/test/testassets/BasicTestApp/ErrorBoundaryTest/ErrorBoundaryCases.razor | Added UI test case for multiple errors scenario |
src/Components/test/E2ETest/Tests/ErrorBoundaryTest.cs | Added E2E test for multiple errors handling |
src/Components/test/testassets/BasicTestApp/ErrorBoundaryTest/ErrorBoundaryCases.razor
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, minor comments about a case we missed and a couple extra tests to capture the new behavior.
Good job!
Fixed the ErrorBoundary multiple errors bug
Description
This pull request enhances error handling in Blazor components, especially around error boundaries and faulted tasks during component initialization and rendering. It introduces new tests and supporting components to ensure that exceptions thrown in lifecycle methods or during rendering are correctly captured by error boundaries, and that error boundaries can handle multiple simultaneous errors.
Changes:
ComponentBase
to avoid callingStateHasChanged
when the initialization task is faulted, preventing unnecessary state updates after errors.ComponentBaseTest.cs
to verify that error boundary capture exceptions from faulted tasks inOnInitializedAsync
and during rendering, and that these errors are surfaced correctly.TestErrorBoundary
andTestComponentErrorBuildRenderTree
test components to simulate and verify error boundary behavior with faulted tasks and rendering errors.Fixes #39814