Repository navigation
fix(history): stamp history depth from the current entry, not history.length (1.x) - #708
Open
sarankumar1325 wants to merge 1 commit into
Open
sarankumar1325 wants to merge 1 commit into
sarankumar1325 wants to merge 1 commit into
Conversation
….length Browsers cap session history (50 entries in Chromium and Firefox). Once the cap is reached, pushState drops the oldest entry and history.length stays the same, so `history.length - 1` gave every new entry the depth of the one below it. Back then computed a zero delta (useBeforeLeave was skipped) and scroll restoration shared one slot between entries. Router and HashRouter now stamp a pushed entry with the current depth + 1, and saveCurrentDepth() stamps an entry the router didn't push (e.g. a #anchor jump) one above the last known depth, falling back to history.length only when no depth is known. Replace keeps the current depth as before. This is the 1.x counterpart of solidjs#695 and solidjs#707 on `next`. Fixes solidjs#694
🦋 Changeset detectedLatest commit: bf196cd The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Fixes #694 (1.x side)
This is the
main(1.x) counterpart of #695 and #707, which fixed the same bug onnext.Problem
saveCurrentDepth()insrc/lifecycle.tsstamps an unstamped entry with_depth: history.length - 1, andset()inRouter/HashRouterpushed the caller's state without a depth, so every router push got stamped that way. Browsers cap session history (50 entries in Chromium and Firefox). Once the cap is reached,pushStatedrops the oldest entry andhistory.lengthstays the same, so each new entry got the same_depthas the one below it. Back then computeddelta = 0, which skippeduseBeforeLeave, and scroll restoration put consecutive entries in the same slot.Change
src/lifecycle.ts:nextDepth(state): stamps a pushed entry with the current entry's depth + 1. It falls back tohistory.length - 1only when no depth is known.saveCurrentDepth(): an entry the router didn't push (e.g. a#anchorjump) is now stamped one above the last known depth instead of fromhistory.length, as fix(history): stamp history depth from the current entry, not history.length #707 does onnext.src/routers/Router.tsandsrc/routers/HashRouter.ts: push withnextDepth(state). Replace still useskeepDepth, and user state is kept.test/history-depth.spec.tsx: four tests.history.lengthmocked at the 50-entry cap: push three times, then replace once. They expect depths[49, 50, 51, 51]. Without the change they get[49, 49, 49, 49].All four tests fail without the
srcchange.Testing
pnpm test(vitest +test:types): 17 files, 263 tests passedpnpm buildAI disclosure: I used an AI assistant to help write this change and its tests. I reviewed the diff and ran the checks above.