Skip to content

fix(history): respect ignoreBlocker in history.go#7832

Open
xianjianlf2 wants to merge 1 commit into
TanStack:mainfrom
xianjianlf2:fix/history-go-ignore-blocker-4867
Open

fix(history): respect ignoreBlocker in history.go#7832
xianjianlf2 wants to merge 1 commit into
TanStack:mainfrom
xianjianlf2:fix/history-go-ignore-blocker-4867

Conversation

@xianjianlf2

@xianjianlf2 xianjianlf2 commented Jul 16, 2026

Copy link
Copy Markdown

What & why

history.go(n, { ignoreBlocker: true }) still fires navigation blockers, unlike back/forward which honor the option (#4867). The internal history adapter's go signature was (n: number) => void, so createHistory.go dropped ignoreBlocker when calling opts.go(index), and the browser go only set nextPopIsGo without setting skipBlockerNextPop. The resulting popstate therefore never bypassed blockers in onPushPopEvent.

Fix (packages/history/src/index.ts, 3 lines)

  • Widen the internal adapter signature to go: (n: number, ignoreBlocker: boolean) => void.
  • createHistory.go forwards the option: opts.go(index, navigateOpts?.ignoreBlocker ?? false).
  • Browser go sets skipBlockerNextPop = true when ignoreBlocker — mirroring the existing back/forward lines exactly.

Tests

New packages/history/tests/createBrowserHistory.test.ts sets up two real jsdom session entries, registers a blocker, and drives an actual go(-1) popstate — asserting the blocker runs for go(-1) and is skipped for go(-1, { ignoreBlocker: true }). This deliberately reaches the browser popstate handler (the gap called out on the prior PR #4872). Verified red→green (without the fix: 1 failed; with: 2 passed); full @tanstack/history suite 27 passed, tsc --noEmit clean.

Closes #4867

Summary by CodeRabbit

  • New Features

    • Added an option to bypass navigation blockers when moving through browser history.
  • Bug Fixes

    • Ensured standard history navigation continues to trigger blockers by default.
    • Added coverage confirming blocker-skipping navigation behaves as expected.

`back` and `forward` set `skipBlockerNextPop` when called with
`ignoreBlocker: true`, so the resulting `popstate` bypasses navigation
blockers. `go` did not forward the option to the browser adapter, so
`history.go(n, { ignoreBlocker: true })` still triggered blockers.

Thread `ignoreBlocker` through the internal `go` adapter and set
`skipBlockerNextPop` in the browser history `go`, matching `back`/`forward`.

Adds a behavioural `createBrowserHistory` regression test that drives a real
`popstate` and asserts blockers run for `go(-1)` but are skipped for
`go(-1, { ignoreBlocker: true })`.

Closes TanStack#4867
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

history.go now forwards ignoreBlocker through the history abstraction, and browser history skips the next blocker check when requested. Tests cover default blocker execution and bypassed navigation.

Changes

History go blocker handling

Layer / File(s) Summary
Propagate the ignore-blocker option
packages/history/src/index.ts
The injected go contract accepts ignoreBlocker, and RouterHistory.go forwards the option with a default of false.
Skip blockers during browser go navigation
packages/history/src/index.ts, packages/history/tests/createBrowserHistory.test.ts
Browser history sets skipBlockerNextPop for ignored navigations; tests verify both blocked and bypassed go(-1) behavior.

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

Possibly related issues

  • TanStack/router issue 7783 — Related to navigation-blocking behavior for programmatic and browser history navigation.

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 matches the main fix: history.go now respects ignoreBlocker.
Linked Issues check ✅ Passed The PR threads ignoreBlocker through history.go and browser history, matching the issue's expected blocker-skip behavior.
Out of Scope Changes check ✅ Passed The signature changes and regression test are directly related to the requested history.go blocker fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/history/src/index.ts`:
- Around line 504-508: Update the if statement in the go callback to wrap the
skipBlockerNextPop assignment in curly braces, preserving the existing behavior
and surrounding history navigation logic.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 472908c1-fdf6-4889-8bc6-09745ce4a9fd

📥 Commits

Reviewing files that changed from the base of the PR and between 0b178a7 and 7aa26ed.

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

Comment on lines +504 to 508
go: (n, ignoreBlocker) => {
if (ignoreBlocker) skipBlockerNextPop = true
nextPopIsGo = true
win.history.go(n)
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Use curly braces for if statements.

The if statement has a one-line body without curly braces. As per coding guidelines, always use curly braces for if, else, loops, and similar control statements.

♻️ Proposed fix
-    go: (n, ignoreBlocker) => {
-      if (ignoreBlocker) skipBlockerNextPop = true
-      nextPopIsGo = true
-      win.history.go(n)
-    },
+    go: (n, ignoreBlocker) => {
+      if (ignoreBlocker) {
+        skipBlockerNextPop = true
+      }
+      nextPopIsGo = true
+      win.history.go(n)
+    },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
go: (n, ignoreBlocker) => {
if (ignoreBlocker) skipBlockerNextPop = true
nextPopIsGo = true
win.history.go(n)
},
go: (n, ignoreBlocker) => {
if (ignoreBlocker) {
skipBlockerNextPop = true
}
nextPopIsGo = true
win.history.go(n)
},
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/history/src/index.ts` around lines 504 - 508, Update the if
statement in the go callback to wrap the skipBlockerNextPop assignment in curly
braces, preserving the existing behavior and surrounding history navigation
logic.

Source: Coding guidelines

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.

history.go does not respect ignoreBlocker option

1 participant