Aspnetcore: Add support for error boundaries in Blazor

Created on 16 Oct 2020  Â·  2Comments  Â·  Source: dotnet/aspnetcore

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 https://github.com/dotnet/aspnetcore/issues/13452 but I'm pulling it out into a separate issue to avoid conflating per-component exception handling with global exception handling.

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

  • Allow users to provide fallback UIs for select component subtrees in the event that there is an exception there
  • Allow users to build apps with cleaner fallback experiences in the event of unexpected UIs
  • Give users more fine-grained control over how failures are handled in the app

Non-goals

  • Implement any kind of global exception handling in Blazor (will leave that tracked in the issue above)
  • Add more sophisticated exception handling to the components in Blazor (besides the APIs needed to build this feature)
affected-medium area-blazor enhancement severity-blocking

Most helpful comment

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 ThirdPartyComponent.razor contains something like this:

@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

All 2 comments

Thanks for contacting us.
We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

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 ThirdPartyComponent.razor contains something like this:

@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

Was this page helpful?
0 / 5 - 0 ratings