Skip to content

fix(history): stamp history depth from the current entry, not history.length - #707

Merged
ryansolid merged 3 commits into
nextfrom
claude/project-thread-fdizuj-694
Oct 28, 2026
Merged

ryansolid merged 3 commits into
nextfrom
claude/project-thread-fdizuj-694

Conversation

@ryansolid

Copy link
Copy Markdown
Member

Fixes #694. This replaces #695 and keeps @sarankumar1325's commit from it. That PR's branch is on a fork this repo's automation can't push to.

From #695

browserHistory().set and hashHistory().set now stamp a pushed entry with depth + 1 instead of history.length - 1. Browsers cap session history at 50 entries in Chromium and Firefox. Once the cap is reached, pushState drops the oldest entry and history.length stops growing. Every new entry then got the same _depth as the one below it, so on Back:

  • delta was 0, so useBeforeLeave never ran;
  • scroll restoration shared one slot between consecutive entries.

Added here

The issue suggested a second fix that #695 left out. saveCurrentDepth() still stamped an entry the router didn't push, such as a #anchor jump, from history.length. It now uses depth + 1 and falls back to history.length - 1 only when no depth is known yet, as on first load. A new test pushes an unrouted entry at the cap and checks that it gets depth 50, not 49.

This PR also merges next in, to pick up the rc.19 test updates from #703.

Tests

  • pnpm test passes (727 client, 102 server), as do pnpm test:types and prettier.

Generated by Claude Code

sarankumar1325 and others added 3 commits October 23, 2026 21:39
…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.

browserHistory() and hashHistory() now stamp a pushed entry with the
current depth + 1. Replace keeps the current depth as before.

Fixes #694
saveCurrentDepth() stamped an entry the router didn't push (e.g. a
#anchor jump) from history.length, which stops growing at the browser's
cap. It now counts up from the last known depth, falling back to
history.length only when none is known.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0117BoWNQHxQ9311k7tQMEKs
@changeset-bot

changeset-bot Bot commented Oct 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ac8c289

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@solidjs/router Patch

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants