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

Blazor: Let browser handle hash change #52583

Closed
davhdavh opened this issue Dec 5, 2023 · 1 comment · Fixed by #53341
Closed

Blazor: Let browser handle hash change #52583

davhdavh opened this issue Dec 5, 2023 · 1 comment · Fixed by #53341
Assignees
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug.
Milestone

Comments

@davhdavh
Copy link
Contributor

davhdavh commented Dec 5, 2023

Background and Motivation

As I can see there are 3 cases with hash:
a. Navigate to a hash on a different page. That was addressed in #8393
b. Blazor uses hash for page navigation. That is #6175 .
c. Navigate to a hash on the current page.

This request is to address the latter.

As I can see there are 3 behaviors that a developer might want:

  1. Let the browser deal with it.
  2. DOM event listener for popstate or hashchange and handle navigation event via javascript.
  3. SSR (current)

The current behavior for blazor.web.js is pretty broken IMHO: Blazor makes a full intercept and a full SSR and then uses the feature from #8393 to navigate to the element.

From the point of view of Blazor 1 and 2 are identical in the fact that if Blazor does nothing, that is the default browser behavior.

Proposed API

Add ignoreHashNavigationOnSamePage to SsrStartOptions.

Alternatively, respect <meta name="ignoreHashNavigationOnSamePage" /> (or something similar), so the individual page can handle it through <HeadContent>.

Alternatively, my preferred behavior: make it the default (It makes no sense to do a SSR on same-page hash change).

Risks

There might be someone somewhere that actually reads url hash server-side.

@mssucksalot
Copy link

@MackinnonBuck Your fix still prevents hashchange event, if I need custom logic in vanilla js to be aside Blazor then I have a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug.
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants
@davhdavh @MackinnonBuck @mssucksalot and others