Skip to content

fix(history): ignore superseded blocker answers - #8909

Open
cgalo wants to merge 1 commit into
TanStack:mainfrom
cgalo:fix/history-stale-blocker-restore
Open

cgalo wants to merge 1 commit into
TanStack:mainfrom
cgalo:fix/history-stale-blocker-restore

Conversation

@cgalo

@cgalo cgalo commented Nov 8, 2026 •

Copy link
Copy Markdown

🎯 Changes

Refs #8878

Also see #8895, which targets the same issue. I left a note there on one case where it reloads the page.

Ignore a blocker answer once a newer popstate, or an accepted push/replace, has superseded it. On main a late "stay" still calls go(-delta). When no popstate comes back, ignoreNextPop stays set and eats the next Back. When one does, the browser lands on the wrong entry.

/a0 ... /a5, on /a2, async blocker
Back, Back, go(2), then answer the Back to /a0 with "stay"

main:  URL jumps to /a4
here:  URL and location stay on /a2

Also skip the restore when the traversal has no index difference (delta is 0 or NaN). go(0) and go(NaN) reload the document, and dropping late answers adds one more way to reach them (Forward waits, push, Back, stay). The tradeoff: a "stay" on such a traversal now keeps the document but leaves URL and router apart, where main reloads.

In the #8878 reproducer, the second Back now reaches the blocker, which is still mounted and asks again. While it waits, URL is /first and router is /new. Leaving puts both on /first. Staying still leaves them apart: the push stored index 3 at position 2, so go(+2) is out of range and ignoreNextPop stays set. That index drift is not addressed here, and #8847 does not change it.

Apps that wait for a restore popstate after answering an obsolete blocker will no longer get one.

Test: 13 unit cases and the first e2e case fail on main
Test: history-blocking e2e in Chromium, Firefox and WebKit
Merges cleanly with #8492 and #8847. Bundle: +12 to +50 B gzip across the 18 scenarios.

AI disclosure: code, tests and this description were drafted with AI (Claude). I reviewed them.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with the relevant test commands, or tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • History navigation now ignores delayed blocker responses when a newer navigation or accepted history change has occurred.
    • Dismissing a blocked traversal with no change in history position no longer triggers a page reload.
    • Added coverage for browser and hash-history traversal, including repeated navigation and entries without router state.

A blocker answer can arrive after a newer popstate or an accepted push
or replace has replaced it. A late "stay" still ran go(-delta). With no
popstate coming back, ignoreNextPop stayed set and ate the next Back.
With one, the browser landed on the wrong entry.

Drop the answer in that case. Also skip the restore when delta is 0 or
NaN, because go(0) and go(NaN) reload the document and dropping a late
answer sends one more sequence there.

This does not fix index drift after a push during a blocked traversal,
so answering "stay" to the next question can still leave the URL and
router apart.

Test: @tanstack/history unit, types and ESLint; history-blocking.spec.ts
in Chromium, Firefox and WebKit
Bug: TanStack#8878
Signed-off-by: Carlos Galo <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@changeset-bot

changeset-bot Bot commented Nov 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fbfc8db

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

This PR includes changesets to release 24 packages
Name Type
@tanstack/history Patch
@tanstack/react-router Patch
@tanstack/router-core Patch
@tanstack/solid-router Patch
@tanstack/start-server-core Patch
@tanstack/vue-router Patch
@tanstack/react-start-client Patch
@tanstack/react-start-rsc Patch
@tanstack/react-start-server Patch
@tanstack/react-start Patch
@tanstack/router-generator Patch
@tanstack/router-plugin Patch
@tanstack/solid-start-client Patch
@tanstack/solid-start-server Patch
@tanstack/start-client-core Patch
@tanstack/start-plugin-core Patch
@tanstack/start-storage-context Patch
@tanstack/vue-start-client Patch
@tanstack/vue-start-server Patch
@tanstack/solid-start Patch
@tanstack/vue-start Patch
@tanstack/router-cli Patch
@tanstack/router-vite-plugin Patch
@tanstack/start-static-server-functions 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

@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The history package now ignores blocker answers made stale by a newer popstate event or location change. It also avoids calling history.go when a blocked traversal has a zero or invalid index delta. Unit and end-to-end tests cover these cases.

Changes: History traversal blocker handling

Layer / File(s) Summary
Stale blocker answer handling
packages/history/src/index.ts, packages/history/tests/staleBlocker.test.ts
The popstate handler tracks events and the current location. It ignores stale blocker answers and reverses blocked traversals only when the index delta is nonzero. Unit tests cover browser and hash histories, stale answers, and traversal outcomes.
End-to-end traversal coverage
e2e/react-router/basic-file-based/tests/history-blocking.spec.ts, .changeset/chilly-sheep-matter.md
End-to-end tests cover same-document traversals followed by pushes and late blocker responses. The changeset declares a patch release for @tanstack/history.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related issues

  • TanStack/router#8878 — The issue describes a stale blocker answer affecting a later Back navigation, which this change addresses.

Possibly related PRs

  • TanStack/router#8895 — This PR changes the same popstate blocker behavior to ignore stale answers, using a navigation ID rather than this change’s pop counter and location check.

Suggested labels: package: history

Suggested reviewers: sheraff, schiller-manuel

Merge Risk: Minimal · up to fbfc8

The change addresses late blocker answers and avoids reloads from zero or invalid restoration deltas. The known index-drift limitation remains, but no new merge-blocking issue was established.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title "fix(history): ignore superseded blocker answers" matches the main change. The changeset and code ignore blocker answers after a newer popstate or accepted history write, which is what the t…
Description check Passed The description covers the main change, the motivation, the reproducer, the tradeoffs, and the test results. It links related issues and PRs. It discloses AI authorship and fills in the Checklist and …
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
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.
Full details: Title check

Explanation

The title "fix(history): ignore superseded blocker answers" matches the main change. The changeset and code ignore blocker answers after a newer popstate or accepted history write, which is what the title describes. It uses a conventional scope and states the change in five words.

Full details: Description check

Explanation

The description covers the main change, the motivation, the reproducer, the tradeoffs, and the test results. It links related issues and PRs. It discloses AI authorship and fills in the Checklist and Release Impact sections. The author checked the changeset box, which matches the raw summary's changeset. The description does not fully follow the template's Changes heading, which uses an emoji header and a comment block. The template comment block's AI-authored rules are followed: disclosure is present and the language is terse. The description meets the template's required information.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 3 files. (1 skipped: 1 unsupported.)

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 70bbd11 and fbfc8db.

Files selected for processing: 4

  • .changeset/chilly-sheep-matter.md
  • e2e/react-router/basic-file-based/tests/history-blocking.spec.ts
  • packages/history/src/index.ts
  • packages/history/tests/staleBlocker.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@agammann agammann left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I checked the new stale-answer guard against the unit and browser tests. The pop counter covers a newer traversal even if it reaches the same entry, while the location identity check covers an accepted push or replace with no intervening popstate. The zero/NaN delta cases also have explicit no-reload coverage, including an end-to-end draft-value assertion. The known index-drift case after a push remains open as described in the PR. This review was drafted with AI assistance from the diff; I did not run tests locally.

This branch has not been deployed

No deployments
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.

2 participants