Skip to content

fix(router-core): handle view transition rejections#7907

Open
David-0x221Eight wants to merge 1 commit into
TanStack:mainfrom
David-0x221Eight:fix/handle-view-transition-rejections
Open

fix(router-core): handle view transition rejections#7907
David-0x221Eight wants to merge 1 commit into
TanStack:mainfrom
David-0x221Eight:fix/handle-view-transition-rejections

Conversation

@David-0x221Eight

@David-0x221Eight David-0x221Eight commented Jul 26, 2026

Copy link
Copy Markdown

Fixes #7906

What changed

  • Keep the ViewTransition returned by document.startViewTransition().
  • Consume rejections from updateCallbackDone, ready, and finished.
  • Ignore expected lifecycle aborts (AbortError and Chromium's hidden-document InvalidStateError).
  • Report unexpected failures once through globalThis.reportError, with console.error as a fallback.
  • Keep update callback failures observable even when they use an expected lifecycle error name.

Why

The View Transitions API creates lifecycle promises immediately. If the document becomes hidden while a transition is starting, Chromium can reject ready with:

InvalidStateError: Transition was aborted because of invalid state

TanStack Router discarded the returned transition object, so this normal lifecycle condition surfaced as a global unhandled rejection even though navigation completed successfully.

Standalone browser reproduction: https://github.com/David-0x221Eight/tanstack-router-view-transition-repro

Validation

  • pnpm test:eslint
  • pnpm test:types
  • pnpm test:unit
  • pnpm nx build router-core
  • Focused View Transition suite: 6 tests passed

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of view transition errors.
    • Prevented expected transition cancellations from generating unnecessary error reports.
    • Ensured unexpected transition failures are reported only once.
    • Added a fallback error-reporting path when the standard reporting API is unavailable.
    • Prevented unhandled errors when view transition updates fail.

@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: 5c669917-fd14-4506-b4bb-8adb2e07fbcf

📥 Commits

Reviewing files that changed from the base of the PR and between fc83c03 and 2526ed8.

📒 Files selected for processing (2)
  • packages/router-core/src/router.ts
  • packages/router-core/tests/view-transition.test.ts

📝 Walkthrough

Walkthrough

RouterCore.startViewTransition now handles view-transition lifecycle rejections, ignores expected aborts, reports unexpected errors once, and falls back to console.error. Tests cover lifecycle failures, update callback errors, deduplication, and cleanup.

Changes

View transition error handling

Layer / File(s) Summary
Handle view-transition lifecycle errors
packages/router-core/src/router.ts
startViewTransition observes lifecycle promises, filters expected aborts, deduplicates reports, and uses globalThis.reportError or console.error.
Validate rejection reporting
packages/router-core/tests/view-transition.test.ts
Tests cover lifecycle rejection classification, fallback logging, update callback failures, single reporting, and test cleanup.

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

Suggested reviewers: schiller-manuel, 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 and concisely describes the main router-core change: handling View Transition promise rejections.
Linked Issues check ✅ Passed The PR matches #7906 by consuming ready/finished rejections, ignoring expected aborts, and reporting unexpected failures once.
Out of Scope Changes check ✅ Passed The changes stay focused on View Transition error handling and its tests, with no obvious unrelated additions.
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.

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.

Handle rejected ViewTransition ready/finished promises

1 participant