Skip to content
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

Reconcile NavigationManager behavior to no longer use NavigationException #59451

Open
javiercn opened this issue Dec 12, 2024 · 2 comments
Open
Labels
area-blazor Includes: Blazor, Razor Components Priority:1 Work that is critical for the release, but we could probably ship without

Comments

@javiercn
Copy link
Member

The behavior NavigationManager exhibits is different in SSR rendering than it is on other interactive modes. In particular, SSR relies on throwing an exception that gets captured by the framework to convert the error into a redirect.

This behavior leads to a poor user experience where users debugging their apps typically see the debugger break when this exception is thrown and incorrectly believe that there is an error/bug on the framework.

In addition to this, code that exists after a call to NavigateTo will continue to execute on interactive render modes but will abruptly stop in SSR scenarios.

The solution for this involves a breaking change, but the number of issues that the current behavior produces justifies such change. We should stop throwing an exception during SSR and instead signal the underlying renderer that a redirection has been requested. We should continue to execute the current ongoing synchronous render batch until completion and, once it finishes, we should dispose the existing renderer and trigger the redirect. This will align the behavior with what happens in other platforms, but we should also have a suite of tests that capture these behaviors across render modes to ensure a consistent experience.

For backcompat reasons we will include an AppContext switch that will continue to throw the exception in case someone needs it.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Dec 12, 2024
@javiercn
Copy link
Member Author

Related issue #53996

@michaelongithub
Copy link

Hi
@javiercn:
contrary to .net 8 using the NavigationManager.NavigateTo in an OnInitilized/Async (Blazor Server) is creating a runtime Error as it did up to .net 6 and now again in .net 9. Would you consider this to be treated with the same idea you proposed or do you think this is another type of problem ? Used this in .net 8 a lot without running into problems. Or just revert back to moving it to OnAfterRender and mange what is displayed before ? Which is cumbersome. Would be interested in your thoughts.

@danroth27 danroth27 changed the title [Blazor] Reconcile NavigationManager behavior Reconcile NavigationManager behavior to no longer use NavigationException Jan 13, 2025
@danroth27 danroth27 added the Priority:1 Work that is critical for the release, but we could probably ship without label Jan 13, 2025
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 Priority:1 Work that is critical for the release, but we could probably ship without
Projects
None yet
Development

No branches or pull requests

3 participants