router.startViewTransition leaves the ready/finished promises unhandled, so a skipped transition throws an unhandled AbortError #8776
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)
schiller-manuel(GitHub profile, opens in a new tab) added labelsinformation needed
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: trueand clicks on the two links:gap between clicks unhandled AbortError 0, 5, 16 ms yes 40, 80, 120 ms no So it is rare for a person, but a transition skipped before its first frame rejects
ready, and the router drops that promise. Wrappingdocument.startViewTransitionso the result getst.ready.catch(() => {})andt.finished.catch(() => {})makes it go away.Chrome 155, @tanstack/react-router 1.170.45.
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:
test result a button that navigates A, B, A, B in quick succession fails: AbortError: Transition was skipped. New ViewTransition startedlink clicks with no pause between them fails: the same AbortErrorlink 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(() => {})andt.finished.catch(() => {})added to the transition returned bydocument.startViewTransition(patched insrc/main.jsxof the clone), all three pass (two runs).schiller-manuel(GitHub profile, opens in a new tab) removed labelsinformation needed
unjica(GitHub profile, opens in a new tab) linked this to #8802
Sign in to join this conversation.
please provide an actual app that reproduces this outside of a test