-
Notifications
You must be signed in to change notification settings - Fork 10.3k
NavigationLock not working with enhanced navigation in an interactive server page component #51436
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
Comments
Hi @marinasundstrom. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
Thanks for reporting this, @marinasundstrom. To clarify, is the scenario that you have an interactive component on the page trying to block enhanced navigation? Or does your scenario only involve statically-rendered components? |
@MackinnonBuck Ah. Forgot. It's when I'm on a page which is an interactive server component. It doesn't block enhanced navigations. The only time the handler is being called is when doing a hard navigation, like a refresh. |
This is expected and by-design (since there is no interactive router), but I can see how this might not be intuitive. We did just make a change recently that makes enhanced navigations invoke the
I'm surprised that the location changing handler runs at all in this case. Or are you referring to the Here's the behavior of navigation events when using server-side routing today (assuming internal navigations if possible):
And here's the behavior when using client-side routing:
I think the things here that are candidates for reconsideration are:
I think if we were going to make one of the two above changes, we should make the second one. This would turn ✅1 into an ❌.
What you think? @marinasundstrom @danroth27 @javiercn @SteveSandersonMS |
@MackinnonBuck Your proposal sounds good to me. I agree it makes the rules simpler. However I've no idea if it would meet the bar for something we'd do before GA, or even if we could plan to bring this as an obscure breaking change into an 8.0.x servicing release based on the idea that we're denoting it as a bug. @mkArtakMSFT |
@MackinnonBuck Yes, it was the |
Thanks for the feedback! We currently have this issue labeled as "docs". If we were to make the change I proposed in my last comment, the docs would be fairly straightforward (a slightly expanded version of the last two bullets in my last comment). However, if we don't make this change, the docs will need to elaborate that "location changing" handlers sometimes get invoked when there's no client-side router. That could definitely seem a bit weird for people using I see us having two options here. Option 1: Make the proposed changeThis would technically a breaking change, even for previous versions of .NET. However, since the vast majority of existing Blazor apps enable navigation interception (client-side routing), I doubt many customers will be relying on the fact that location changing handlers get invoked for programmatic navigations when navigation interception is disabled. There is also the concern that it's too late to make this change in .NET 8, and it's too breaking to include in a patch release (because at that point, there will be many customers using server-side routing, which would invalidate my previous point about customers not being affected by the change in behavior). However, as mentioned previously, this behavior is much easier to explain. Option 2: Strategically document the existing behaviorAlternatively, we could keep the existing behavior and document it such that we could make enhancements without it being considered breaking. We could say something like this: "When server-side routing is enabled, location changing handlers may or may not intercept internal navigations. It's important that app logic not rely on location changing handlers being called consistently. For example, the user might switch to another page before an interactive runtime becomes available." This statement would still be true if we enable navigation cancellation for other types of navigations in the future, so it's probably good advice no matter how many different scenarios are supported. If we want to be more precise, we could amend this with something like: "In .NET 8, if server-side routing is enabled, location changing handlers will only get invoked for programmatic navigations initiated from an interactive runtime. In future .NET versions, more types of navigations (e.g., link clicks) may also invoke location changing handlers". Thoughts? @mkArtakMSFT @SteveSandersonMS |
@guardrex could we add some content to the "Blazor routing and navigation" docs about how the The table above shows the cases where each event gets called, but we probably don't need a table like that in the docs. We could summarize the behavior as: "When an enhanced navigation occurs, |
Is there an existing issue for this?
Describe the bug
NavigationLock doesn't activate when navigation away using link that triggers enhanced navigation in an interactive server page component. (For instance a link in the navbar)
Only works on page refresh.
Expected Behavior
The
OnBeforeInternalNavigation
should be triggered on enhanced navigation to another page.Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
8.0.100-rc.2.23502.2
Anything else?
No response
The text was updated successfully, but these errors were encountered: