Skip to content

Reconcile NavigationManager behavior to no longer use NavigationException #59451

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

Open
javiercn opened this issue Dec 12, 2024 · 9 comments · May be fixed by #61306
Open

Reconcile NavigationManager behavior to no longer use NavigationException #59451

javiercn opened this issue Dec 12, 2024 · 9 comments · May be fixed by #61306
Assignees
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
@danroth27 danroth27 marked this as a duplicate of #53996 Feb 5, 2025
@indcoder
Copy link

Sorry, I do not agree with the categorization of this issue as a feature request for .NET 10; its a bug in .NET 9. This behaviour is a breaking change from .NET 8 and was not documented to work in this fashion. This negates the existing SSR/prerendering modes for our App architecture, forcing us to make the whole app Interactive from the getgo increasing the latency of our first/landing page

Image

@javiercn
Copy link
Member Author

javiercn commented Feb 25, 2025

@indcoder thanks for contacting us.

This behavior hasn't changed between .NET 8.0 and .NET 9.0.

During prerendering we've always thrown a NavigationException and triggered a re-render, even in the old Blazor Server model.

@pavelsavara
Copy link
Member

forcing us to make the whole app Interactive from the getgo

@indcoder could you please describe your previous and current experience in more detail ?
Are you talking about NavigationException ? Are you talking about behavior in VS debugger or something else ?

@javiercn
Copy link
Member Author

javiercn commented Feb 25, 2025

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.

This behavior hasn't changed between 6,7,8 or 9. During prerendering, NavigationManager.NavigateTo has always thrown a NavigationException.

The purpose of this issue is to get rid of the NavigationException because it causes issues, and we want to make sure we align the behavior across different render modes.

@indcoder
Copy link

Hi @pavelsavara @javiercn I encountered this issue circa Dec'24 when implementing IAM for the app. Searched on GH...and it was identical to Adam's experience adamfoneil/CardGameSDK#16 who also has referenced this issue. I didn't revert back to 8 nor take screenshots/video since ours was a relatively greenfield project but rather opted for global interactivity with prerendering disabled. And I only revisited this issue since Aspire 9.1 was about to be released.

This issue was always one of the caveats we had to give when folks try out Blazor and start implementing IAM https://x.com/hackmum/status/1878801401759043931, and I thought it was high enough in the priority to tackle it early. I am now reconciled to the fact that this will be solved only by the .NET 10 timeframe and I'm glad to see IAM story in Blazor getting a larger mindshare in .NET 10 @danroth27

Image

Because the arduous workaround to adopt a minimally adequate security posture for Blazor Web App has been its Achilles heel for its adoption. Even the movie sample app that @guardrex references this issue does not implement IAM

Also, hopefully for .NET 10, while we are at it, the IAM chain is being holistically examined to make it frictionless for folks to secure their Blazor app across any combination of render modes, in the process jettisoning the remnants of .NET framework in the IAM chain e.g.: 👇

Image

@javiercn
Copy link
Member Author

@indcoder thanks for the additional details.

It's unclear to us how what you are describing is related to this issue. If there's anything that you want to propose or that you have problems with, could you please file a separate issue describing the concrete problem that you are having and what you are proposing to that regard?

Thanks.

@javiercn javiercn assigned ilonatommy and unassigned pavelsavara Mar 10, 2025
@nvmkpk
Copy link
Contributor

nvmkpk commented Mar 14, 2025

Also, there is one more inconsistency between the interactive modes and SSR, if I pass in a value of true for replace parameter, in case of SSR, it doesn't actually replace the current URL but navigates to the new URL leaving the previous one in the history.

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

Successfully merging a pull request may close this issue.

7 participants