-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Add support for error boundaries in Blazor #26953
Comments
Thanks for contacting us. |
This would be wonderful. At a motivating use case, here’s a situation I can’t currently handle in Blazor: <div>
<MyComponent />
<ThirdPartyComponent Attr=“null” />
</div> where @code {
[Parameter] public string Attr { get; set; }
}
<p>@Attr.ToLower()</p> Right now, there’s no way to salvage the render tree and display at least MyComponent, due to the failure to handle errors inside the other Component |
Just adding my $0.02. I would also love to see Blazor have something similar to React's Error Boundaries. From my perspective, it is difficult to consider Blazor as being production ready until it has this type of a feature. There is no way that a single small unhandled exception in a developer's code, or worse - a third-party component's code, should cripple an entire application unless a developer wishes for that to happen. When an MVC app or WebForms app has an isolated exception, it does not kill the application. But Blazor? Game over. If using Blazor Server, the user's SignalR connection is nuked and state is lost. Not very fun being a developer and having to explain this to management and end users. If Blazor had something like a React Error Boundary, only the faulty component could be disabled showing a user-friendly error message and the rest of the application could continue to function as expected. I see this issue currently has a Priority Level of 2. Personally, I would make it even higher priority. Application stability is a fundamental requirement. |
@SteveSandersonMS Are you thinking that the "global" aspect of #13452 could be handled by the user adding the solution in this issue to a sufficiently high component in the hierarchy, e.g. App.razor? |
Yes, if you find it useful to put in error handling logic there. |
Done in #30874 |
Summary
This proposes adding an error boundaries feature to Blazor, as inspired by the implementation in React. This feature would allow developers to implement logic on individual components to capture any excpetions, log, display a fallback UI, send telemetry, etc.
This feature was proposed in #13452 but I'm pulling it out into a separate issue to be more precise about the proposed solution.
Motivation
A meaningfully complex Blazor app will contain numerous components, both first-party and third-party. There's no way to guarantee that all exception cases will be handled in a component. There's also no way to indicate that even though an unhandled exception occurred in one part of the app, that the entire app is not compromised.
Goals
Non-goals
ILogger
for logging, and beyond that, truly unhandled exceptions mean the app is in an undefined state which is unsafe to continue)The text was updated successfully, but these errors were encountered: