Skip to content

fix(history): restore blocked pop navigation by delta - #7908

Open
erictheswift wants to merge 1 commit into
TanStack:mainfrom
erictheswift:fix/history-blocked-pop-rollback
Open

fix(history): restore blocked pop navigation by delta#7908
erictheswift wants to merge 1 commit into
TanStack:mainfrom
erictheswift:fix/history-blocked-pop-rollback

Conversation

@erictheswift

@erictheswift erictheswift commented Jul 26, 2026

Copy link
Copy Markdown

Problem

When a browser POP is blocked, createBrowserHistory always calls
window.history.go(1) to undo it. That only reverses a single-entry Back:

  • blocking Forward attempts to move farther forward instead of returning;
  • blocking go(-2) returns only one entry, leaving the browser URL and the
    router's current location on different history entries.

Fix

Undo the observed POP with its inverse delta: window.history.go(-delta).
For Back this remains go(1), while Forward and multi-entry GO operations now
return to the exact entry from which navigation started.

Tests

Added browser-history regressions for:

  • a blocked Forward;
  • a blocked multi-entry go(-2).

Validated with:

CI=1 NX_DAEMON=false pnpm nx run @tanstack/history:test:unit --outputStyle=stream --skipRemoteCache
CI=1 NX_DAEMON=false pnpm nx run @tanstack/history:test:types --outputStyle=stream --skipRemoteCache
CI=1 NX_DAEMON=false pnpm nx run @tanstack/history:test:eslint --outputStyle=stream --skipRemoteCache
pnpm exec prettier --check packages/history/src/index.ts packages/history/tests/createBrowserHistory.test.ts

The new tests fail on main with the browser at /two instead of /one for
Forward and /two instead of /three for go(-2), then pass with the inverse
delta.

Summary by CodeRabbit

  • Bug Fixes

    • Corrected browser-history restoration when blocked back, forward, or multi-step navigation occurs.
    • Ensured the exact original page is restored after blocked navigation attempts.
  • Tests

    • Added coverage for blocked single-step and multi-step browser history navigation.

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d7acba48-65fa-41d8-bda4-136476e9b221

📥 Commits

Reviewing files that changed from the base of the PR and between 179d9b9 and 09c1d1e.

📒 Files selected for processing (2)
  • packages/history/src/index.ts
  • packages/history/tests/createBrowserHistory.test.ts

📝 Walkthrough

Walkthrough

Blocked browser-history pop navigations now roll back using the inverse computed delta. Tests cover restoration after blocked forward navigation and blocked multi-entry navigation.

Changes

Browser history rollback

Layer / File(s) Summary
Delta-based rollback and restoration tests
packages/history/src/index.ts, packages/history/tests/createBrowserHistory.test.ts
Blocked pop navigations call history.go(-delta), with tests verifying restoration of the original entry for forward and multi-step navigation and confirming blocker invocation.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: sheraff

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly captures the main change: fixing blocked history pop navigation rollback to use the computed delta.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant