Ignore hash-only popstate navigation#1216
Merged
Merged
Conversation
Deploying redwood-sdk-docs with
|
| Latest commit: |
6171687
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://30b911c5.redwood-sdk-docs.pages.dev |
| Branch Preview URL: | https://fix-hash-popstate-navigation.redwood-sdk-docs.pages.dev |
eb184b9 to
ab9241e
Compare
Reported-by: Adam Dehnel <1697162+arsdehnel@users.noreply.github.com> Co-authored-by: Adam Dehnel <1697162+arsdehnel@users.noreply.github.com>
ab9241e to
6171687
Compare
justinvdm
approved these changes
Jun 2, 2026
justinvdm
left a comment
Collaborator
There was a problem hiding this comment.
Thank you @arsdehnel @peterp!
justinvdm
added a commit
that referenced
this pull request
Jun 4, 2026
Cherry-picked from a5ac6e3, manually resolved to fit current scroll-restoration code (pendingScroll instead of ScrollRestorationController). Client navigation now remembers the current pathname + search. When popstate fires but only the hash changed, it lets the browser handle the anchor scroll on its own and skips the RSC navigation. Fixes #1215. Co-authored-by: Adam Dehnel <1697162+arsdehnel@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Same-page anchor links could jump to the right heading, then immediately jump back to the top. This happened because the browser fired
popstatefor a hash-only URL change, and Redwood treated it like a full client navigation. The bug showed up on the RedwoodSDK docs site when using table-of-contents links.Fixes #1215.
Solution
Client navigation now remembers the current
pathname + search. Whenpopstatefires but only the hash changed, it lets the browser handle the anchor scroll on its own and skips the RSC navigation. The docs site usesrwsdkfrom the workspace, so it gets this fix the next time it deploys from this code.Technical Summary
location.hash.navigate()pushes or replaces history, so normal route changes still work.popstatehandler only when the path key did not change.popstatedoes not callonNavigate, does not fetch a navigation payload, and does not apply pending scroll.Credit
Thanks to @arsdehnel for reporting this, explaining the root cause, and proposing the path-key fix in #1215.