Skip to content

[release/8.0] [Blazor] Prevent error boundaries from handling exceptions of type NavigationException #53968

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

Merged
merged 1 commit into from
Feb 12, 2024

Conversation

MackinnonBuck
Copy link
Member

Prevent error boundaries from handling exceptions of type NavigationException

Backport of #53826

Fixes an issue where error boundaries may handle NavigationException instances and treat them as uncaught errors rather than signals to redirect.

Description

The implementation of NavigationManager.NavigateTo() for static server rendering (SSR) always throws a NavigationException. This exception does not communicate an error but acts as a message to be caught by the framework so a redirect can be initiated.

Blazor also provides an ErrorBoundary component (unrelated to the above) that catches exceptions thrown from within child components, so that errors disable only part of the UI rather than crash the entire page. However, before this PR, the ErrorBoundary component did not account for the fact that exceptions of type NavigationException are not critical errors and need to bubble all the way up to be handled by the framework. As a result, error boundaries would prevent child components from being able to initiate redirects during static server rendering.

This PR updates Blazor's renderer to exclude NavigationException instances from being reported to error boundaries.

Fixes #52777

Customer Impact

We've received multiple reports of customers getting confused by this exception without knowing that its existence is what enables navigation during static server rendering. When an ErrorBoundary catches and displays this exception, many customers are left to believe that the NavigationException is being thrown as a result of navigation not succeeding. Ugly workarounds may exist, like restructuring app logic to ensure that NavigationManager APIs are not used within error boundaries, but something as fundamental as navigation is expected to work without this type of issue.

Regression?

  • Yes
  • No

This bug has existed since the ability to redirect from within a component was introduced in .NET 8.

Risk

  • High
  • Medium
  • Low

The fix works by adding a special case for NavigationException without changing other functionality, so it's unlikely that a regression will be introduced here.

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

@MackinnonBuck MackinnonBuck added Servicing-consider Shiproom approval is required for the issue area-blazor Includes: Blazor, Razor Components labels Feb 12, 2024
@MackinnonBuck MackinnonBuck requested a review from a team as a code owner February 12, 2024 18:47
@dotnet-policy-service dotnet-policy-service bot added this to the 8.0.x milestone Feb 12, 2024
@mkArtakMSFT mkArtakMSFT added Servicing-approved Shiproom has approved the issue and removed Servicing-consider Shiproom approval is required for the issue labels Feb 12, 2024
@wtgodbe wtgodbe merged commit f734954 into release/8.0 Feb 12, 2024
@wtgodbe wtgodbe deleted the mbuck/backport-53826-to-8.0 branch February 12, 2024 21:19
@dotnet-policy-service dotnet-policy-service bot modified the milestones: 8.0.x, 8.0.3 Feb 12, 2024
@dotnet-policy-service dotnet-policy-service bot added the area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework label Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework Servicing-approved Shiproom has approved the issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants