Skip to content

Trigger LocationChanging callbacks on enhanced navigation #48766

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
SteveSandersonMS opened this issue Jun 13, 2023 · 1 comment
Open

Trigger LocationChanging callbacks on enhanced navigation #48766

SteveSandersonMS opened this issue Jun 13, 2023 · 1 comment
Labels
area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-navigation feature-full-stack-web-ui Full stack web UI with Blazor Pillar: Complete Blazor Web Priority:1 Work that is critical for the release, but we could probably ship without
Milestone

Comments

@SteveSandersonMS
Copy link
Member

SteveSandersonMS commented Jun 13, 2023

Location changing handlers may not always be invoked on enhanced navigation. For example, when no interactive router is present, interactive components cannot intercept user-initiated navigations.

From @MackinnonBuck:

"When an enhanced navigation occurs, LocationChanged event handlers registered in interactive runtimes (i.e., Blazor Server/WebAssembly) get invoked. However, location changing handlers may or may not intercept enhanced navigations, so it's important that app logic not rely on location changing handlers being invoked reliably. For example, the user might switch to another page before an interactive runtime becomes available. In .NET 8, if server-side routing and enhanced navigation are 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".

A more detailed analysis of when location changing handlers get invoked can be found here.

@SteveSandersonMS SteveSandersonMS added area-blazor Includes: Blazor, Razor Components feature-full-stack-web-ui Full stack web UI with Blazor labels Jun 13, 2023
@SteveSandersonMS SteveSandersonMS added this to the 8.0-preview7 milestone Jun 13, 2023
@mkArtakMSFT mkArtakMSFT modified the milestones: 8.0-preview7, 8.0-rc1 Jul 11, 2023
@mkArtakMSFT mkArtakMSFT added the enhancement This issue represents an ask for new feature or an enhancement to an existing one label Jul 31, 2023
@MackinnonBuck MackinnonBuck modified the milestones: 8.0-rc1, 8.0-rc2 Aug 10, 2023
@mkArtakMSFT mkArtakMSFT modified the milestones: 8.0-rc2, .NET 9 Planning Aug 21, 2023
mkArtakMSFT pushed a commit that referenced this issue Oct 13, 2023
…eractive components when using SSR routing (#51279)

# Invoke `LocationChanged` for interactive components when an enhanced navigation occurs

This PR makes the `LocationChanged` event get invoked for interactive runtimes when an enhanced navigation occurs.

## Description

This PR makes the following changes:
* The `LocationChanged` event gets invoked for all interactive runtimes when either a client-side or enhanced navigation occurs
  * Previously:
    * An enhanced navigation would have not invoked the `LocationChanged` event in interactive runtimes
    * A client-side navigation would only invoke the `LocationChanged` event for the runtime that started most recently
* Attempting to enable interactive routing from multiple interactive runtimes results in an error at runtime
* If an interactive router is present but multiple runtimes are available, the `LocationChanging` event only gets invoked for the runtime that has the interactive router
  * It would take additional work to allow either runtime to cancel a client-side navigation, and that's outside the scope of this PR. We have #48766 to track doing the extra work to support this scenario

Fixes #51216

## Customer Impact

Without this changes the customers will encounter problems with UI being correctly updated during enhanced navigation because `LocationChanging` event not firing. 

Besides the UI not updating correctly this will also cause customer registered handlers for the `LocationChanged` event not firing resulting in unexpected behaviors.

## Regression?

- [ ] Yes
- [x] No

[If yes, specify the version the behavior has regressed from]

## Risk

- [ ] High
- [ ] Medium
- [x] Low

Despite the size of this change, we have quite extensive automated tests (including these newly added ones) around the interactive routing scenarios, so we expect that nothing will break from this change.

## Verification

- [x] Manual (required)
- [x] Automated

## Packaging changes reviewed?

- [ ] Yes
- [x] No
- [ ] N/A

----

## When servicing release/2.1

- [ ] Make necessary changes in eng/PatchConfig.props

---------

Co-authored-by: Surayya Huseyn Zada <[email protected]>
Co-authored-by: Surayya Huseyn Zada <[email protected]>
@ghost
Copy link

ghost commented Dec 20, 2023

Thanks for contacting us.

We're moving this issue to the .NET 9 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@mkArtakMSFT mkArtakMSFT changed the title Trigger navigation callbacks in all Blazor hosts Trigger LocationChanging callbacks on enhanced navigation Jan 17, 2024
@SteveSandersonMS SteveSandersonMS added the Priority:1 Work that is critical for the release, but we could probably ship without label Jan 18, 2024
3dots pushed a commit to 3dots/aspnetcore-Web.JS that referenced this issue Feb 19, 2024
…eractive components when using SSR routing (#51279)

# Invoke `LocationChanged` for interactive components when an enhanced navigation occurs

This PR makes the `LocationChanged` event get invoked for interactive runtimes when an enhanced navigation occurs.

## Description

This PR makes the following changes:
* The `LocationChanged` event gets invoked for all interactive runtimes when either a client-side or enhanced navigation occurs
  * Previously:
    * An enhanced navigation would have not invoked the `LocationChanged` event in interactive runtimes
    * A client-side navigation would only invoke the `LocationChanged` event for the runtime that started most recently
* Attempting to enable interactive routing from multiple interactive runtimes results in an error at runtime
* If an interactive router is present but multiple runtimes are available, the `LocationChanging` event only gets invoked for the runtime that has the interactive router
  * It would take additional work to allow either runtime to cancel a client-side navigation, and that's outside the scope of this PR. We have dotnet/aspnetcore#48766 to track doing the extra work to support this scenario

Fixes #51216

## Customer Impact

Without this changes the customers will encounter problems with UI being correctly updated during enhanced navigation because `LocationChanging` event not firing. 

Besides the UI not updating correctly this will also cause customer registered handlers for the `LocationChanged` event not firing resulting in unexpected behaviors.

## Regression?

- [ ] Yes
- [x] No

[If yes, specify the version the behavior has regressed from]

## Risk

- [ ] High
- [ ] Medium
- [x] Low

Despite the size of this change, we have quite extensive automated tests (including these newly added ones) around the interactive routing scenarios, so we expect that nothing will break from this change.

## Verification

- [x] Manual (required)
- [x] Automated

## Packaging changes reviewed?

- [ ] Yes
- [x] No
- [ ] N/A

----

## When servicing release/2.1

- [ ] Make necessary changes in eng/PatchConfig.props

---------

Co-authored-by: Surayya Huseyn Zada <[email protected]>
Co-authored-by: Surayya Huseyn Zada <[email protected]>
@mkArtakMSFT mkArtakMSFT removed this from the .NET 10 Planning milestone Nov 12, 2024
@mkArtakMSFT mkArtakMSFT added this to the Backlog milestone Nov 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 enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-navigation feature-full-stack-web-ui Full stack web UI with Blazor Pillar: Complete Blazor Web 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