Skip to content

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

Closed
xianjianlf2 wants to merge 4 commits into
TanStack:mainfrom
xianjianlf2:fix/history-go-ignore-blocker-4867
Closed

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

Conversation

@xianjianlf2

@xianjianlf2xianjianlf2 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.
    • Standard history navigation continues to check registered blockers by default.
  • Bug Fixes

    • Ensured blocker checks are consistently applied during normal history navigation.
  • Tests

    • Added coverage for both blocked navigation and navigation with blocker checks bypassed.

`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 })`.
ClosesTanStack#4867
@coderabbitai

coderabbitaiBot commented Jul 16, 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: 679f882e-7761-4c2e-93f5-6856608582da

📥 Commits

Reviewing files that changed from the base of the PR and between 783f883 and 576b442.

📒 Files selected for processing (2)
  • packages/history/src/index.ts
  • packages/history/tests/createBrowserHistory.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/history/src/index.ts
  • packages/history/tests/createBrowserHistory.test.ts

📝 Walkthrough

Walkthrough

history.go now forwards ignoreBlocker through the history abstraction. Browser history skips the next blocker check when requested. Tests cover blocked 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 default blocker execution and bypassed go(-1) behavior. Test cleanup destroys each active history instance.

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

Possibly related PRs

  • TanStack/router#7908: Both changes modify browser history POP navigation and blocker handling. This PR addresses go blocker bypass, while that PR fixes rollback by delta.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedThe title clearly describes the fix to make history.go respect the ignoreBlocker option.
Linked Issues check✅ PassedThe changes implement issue #4867 by forwarding ignoreBlocker and setting skipBlockerNextPop for go navigation.
Out of Scope Changes check✅ PassedThe implementation and regression tests remain within the linked issue scope.
Docstring Coverage✅ PassedNo 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.

@coderabbitaicoderabbitaiBot 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 threadpackages/history/src/index.ts
@xianjianlf2

Copy link
Copy Markdown
Author

Addressed the CodeRabbit style follow-up in ef44d1e by wrapping the ignoreBlocker branch in history.go with braces.

Local check:

pnpm --filter @tanstack/history exec vitest run tests/createBrowserHistory.test.ts

Result: 1 file / 2 tests passed, no type errors.

…-blocker-4867
# Conflicts:
#	packages/history/tests/createBrowserHistory.test.ts
@coderabbitai

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@xianjianlf2

Copy link
Copy Markdown
Author

Merged latest origin/main into fix/history-go-ignore-blocker-4867 and resolved the add/add history test conflict by keeping the new browser-history queue tests plus the go(..., { ignoreBlocker: true }) blocker coverage.

Validation:

  • pnpm install --frozen-lockfile
  • pnpm exec prettier --check packages/history/src/index.ts packages/history/tests/createBrowserHistory.test.ts
  • pnpm --dir packages/history run build
  • pnpm --dir packages/history exec vitest run tests/createBrowserHistory.test.ts (6 passed, no type errors)

Current head: 576b442e31b1c0060f5e6c603fcba7f2c1d8a7ee

@xianjianlf2

Copy link
Copy Markdown
Author

Closing this because #8264 has now landed on main with the same go(..., { ignoreBlocker: true }) fix and broader handling for back, forward, and beforeunload. I synced this branch with the current main and verified the @tanstack/history unit, type, build, and ESLint targets.

Sign up for freeto 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

@xianjianlf2