Skip to content
Source
Sign inSign up
TanStack/router

router.startViewTransition leaves the ready/finished promises unhandled, so a skipped transition throws an unhandled AbortError #8776

Openmokevnin(GitHub profile, opens in a new tab) opened this issue 3 comments

Describe the bug

With defaultViewTransition: true, router.startViewTransition (router-core/src/router.ts) calls document.startViewTransition(fn).updateCallbackDone and drops the ViewTransition object. Its ready and finished promises get no handler.

updateCallbackDone settles when the DOM update is done, well before the animation ends. So any navigation that starts while the previous cross-fade is still animating skips that transition, the browser rejects its ready with AbortError: Transition was skipped. New ViewTransition started, and nothing handles the rejection. await router.navigate() does not prevent it, because it resolves on updateCallbackDone.

In an app this is console noise on quick consecutive navigations. In a test runner (vitest browser mode) it fails the whole run: every test passes, then vitest reports "Unhandled Rejection" and exits non-zero.

Reproduction

Vitest browser mode (chromium), no UI needed:

import { createMemoryHistory, createRootRoute, createRoute, createRouter } from '@tanstack/react-router'
import { test } from 'vitest'

test('two navigations in a row', async () => {
  const root = createRootRoute()
  const a = createRoute({ getParentRoute: () => root, path: '/a' })
  const b = createRoute({ getParentRoute: () => root, path: '/b' })
  const router = createRouter({
    routeTree: root.addChildren([a, b]),
    history: createMemoryHistory({ initialEntries: ['/a'] }),
    defaultViewTransition: true,
  })
  await router.load()
  await router.navigate({ to: '/b' })
  await router.navigate({ to: '/a' })
})

Result: the test passes, then Unhandled Rejection: AbortError: Transition was skipped. New ViewTransition started and a failing exit code.

Expected behavior

A skipped transition is not an error for the app. The router should attach a no-op handler to ready and finished of the transition it starts.

Verified

Wrapping document.startViewTransition so the returned object gets t.ready.catch(() => {}) and t.finished.catch(() => {}) removes the error completely (0 errors in the same repro).

Versions

@tanstack/react-router 1.170.45, @tanstack/router-core 1.171.38, Chromium (vitest browser mode)

  1. please provide an actual app that reproduces this outside of a test

  2. schiller-manuel(GitHub profile, opens in a new tab) added labelsinformation needed

  3. Here is a standalone app, no test runner: https://github.com/mokevnin/tanstack-router-view-transition-repro

    npm install && npm run dev

    Open it in Chrome and press "Navigate A, B, A, B right away". The counter under the links shows the unhandled rejections and the console prints Uncaught (in promise) AbortError: Transition was skipped. New ViewTransition started (3 per press, every time).

    By hand it needs two navigations within about one frame, e.g. a double click or a redirect chain. Measured with defaultViewTransition: true and clicks on the two links:

    gap between clicksunhandled AbortError
    0, 5, 16 msyes
    40, 80, 120 msno

    So it is rare for a person, but a transition skipped before its first frame rejects ready, and the router drops that promise. Wrapping document.startViewTransition so the result gets t.ready.catch(() => {}) and t.finished.catch(() => {}) makes it go away.

    Chrome 155, @tanstack/react-router 1.170.45.

  4. I added Playwright tests to the repro repo (real Chrome, against the running app): https://github.com/mokevnin/tanstack-router-view-transition-repro

    npm install && npm test

    An unhandled promise rejection counts as a failure:

    testresult
    a button that navigates A, B, A, B in quick successionfails: AbortError: Transition was skipped. New ViewTransition started
    link clicks with no pause between themfails: the same AbortError
    link clicks 120 ms apart (control)passes

    I ran it from a fresh clone three times: the same two fail and the control passes every time. With t.ready.catch(() => {}) and t.finished.catch(() => {}) added to the transition returned by document.startViewTransition (patched in src/main.jsx of the clone), all three pass (two runs).

  5. schiller-manuel(GitHub profile, opens in a new tab) removed labelsinformation needed

Sign in to join this conversation.