Sub topic 13
Skipping and interrupted transitions
This chapter assumes you can call document.startViewTransition(), you know the three promises on the returned ViewTransition object (ready, updateCallbackDone, finished), and you are comfortable with promises and async/await. Earlier chapters showed the normal path, where the browser captures the old state, runs your callback, captures the new state, and animates. Here you will learn what happens when that path is cut short, and how to write code that stays correct either way.
The rule: the DOM update always wins
A view transition is decoration around a DOM update. If the browser cannot or will not animate, it skips the transition. In almost every case it still runs your update callback, so the page ends up in the right state without motion.
Treat the animation as optional and the update as mandatory. Any code that depends on the new DOM belongs in the callback or after updateCallbackDone. Code that depends on the animation having played is fragile.
Ways a transition gets skipped
| Cause | Does the update callback run? | `ready` | `finished` |
|---|---|---|---|
| You call `transition.skipTransition()` | Yes, if it has not run yet | Rejects (`AbortError`) if it had not resolved yet | Resolves once the callback finishes |
| A newer `startViewTransition()` call starts | Yes, for the older transition | Rejects if it had not resolved yet | Resolves once the callback finishes |
| The document is hidden (background tab) | Yes | Rejects with `InvalidStateError` | Resolves once the callback finishes |
| Two elements share a `view-transition-name` in one state | Yes | Rejects with `InvalidStateError` | Resolves once the callback finishes |
| The callback throws or returns a rejected promise | It ran, and failed | Rejects with that error | Rejects with that error |
Two details matter in practice:
- If
readyhad already resolved when the skip happened, the animation was running. The browser ends it immediately andfinishedstill resolves. finishedonly rejects when your own callback fails. A skipped transition is not an error from the page's point of view.
Handling the promises
The browser marks ready as handled, so a skipped transition does not log an unhandled rejection for it. That protection does not cover updateCallbackDone or finished. If your callback throws and nothing handles those promises, the console reports an unhandled rejection.
Code that animates after ready must expect it to reject:
async function navigate(nextId) {
if (!document.startViewTransition) {
updateView(nextId);
return;
}
const transition = document.startViewTransition(() => updateView(nextId));
try {
await transition.ready;
document.documentElement.animate(
{ clipPath: ['inset(0 0 100% 0)', 'inset(0)'] },
{
duration: 400,
easing: 'ease-in',
pseudoElement: '::view-transition-new(root)'
}
);
} catch (error) {
// Skipped: no pseudo-elements exist. The DOM update still happens.
console.debug('View transition skipped:', error.name);
}
try {
await transition.updateCallbackDone;
} catch (error) {
console.error('Update failed:', error);
throw error;
}
}Without the first try, the code would reach animate() only on success, but the surrounding function would still reject for a harmless skip. With it, a skip is a normal outcome.
Interruption: a new transition replaces a running one
Only one view transition runs per document at a time. Calling startViewTransition() while another is in progress skips the older one. Its animation jumps to the end, and its update callback still runs, so state changes are never dropped. The new transition then captures the page as it looks at that moment.
This produces a visible jump when users click quickly. The old animation snaps to its final frame, and the new one starts from there. For fast, repeated actions such as paging through a list, there are three common responses:
- Accept the jump. Short animations, around 200 to 300 ms, make it hard to notice.
- Skip the animation for rapid repeats by calling
skipTransition()yourself. - Ignore or queue input while a transition runs.
The second option looks like this:
let activeTransition = null;
function goTo(nextId) {
if (!document.startViewTransition) {
updateView(nextId);
return Promise.resolve();
}
// A transition is already running: update at once, no animation.
if (activeTransition) {
activeTransition.skipTransition();
updateView(nextId);
return Promise.resolve();
}
const transition = document.startViewTransition(() => updateView(nextId));
activeTransition = transition;
transition.finished
.catch(() => {})
.finally(() => {
if (activeTransition === transition) activeTransition = null;
});
return transition.updateCallbackDone;
}The finally block compares identity before clearing, so a late-finishing old transition cannot erase the reference to a newer one. The catch(() => {}) handles a failing callback so the chain does not leave an unhandled rejection. Report the real error through the promise that goTo returns.
Calling skipTransition() and then updateView() yourself is safe here because the first transition's callback has already run by the time it is animating. If you call skipTransition() before the callback runs, the browser runs the callback for you, so do not also call it by hand.
The page is not interactive during a transition
While the pseudo-element tree is on screen, it covers the page. In Chrome, clicks during that time do not reach the elements underneath. With a 300 ms animation this is rarely noticeable. A long or stuck transition makes the page feel frozen. Two habits help:
- Keep animations short.
- Keep the update callback fast. Rendering is paused from the moment the old state is captured until your callback's promise settles, so a slow
fetchinside the callback freezes the page.
Fetch first, then start the transition with the data in hand:
async function showItem(id) {
const html = await fetchItemHtml(id); // page stays live while this runs
document.startViewTransition(() => {
document.querySelector('#content').innerHTML = html;
});
}Cleanup that survives a skip
Dynamic view-transition-name values, as in the shared-element example, must be removed even if the transition is skipped. finished settles in every case except a failing callback, and .finally() runs even then. That is why cleanup belongs there:
const transition = document.startViewTransition(() => showDetail(id));
transition.finished.finally(() => {
card.style.viewTransitionName = '';
});Leaving the name behind is a common cause of duplicate-name errors on the next transition. That error skips the new transition, and the cause then looks unrelated to the one that left the name.
Lifecycle with the exits marked
Debugging checklist
When a transition does not animate, work through these in order:
- Log
transition.ready.catch(e => console.log(e)). AnInvalidStateErrorusually means a duplicate name or a hidden tab. - Search the DOM for repeated
view-transition-namevalues, including names set through inline styles that were never cleared. - Check whether another
startViewTransition()call fires right after yours, such as from a second event handler or a re-render. - Confirm the callback does not throw. Check
updateCallbackDonefor a rejection.
Exercise
A user clicks "Next" three times in quick succession. Each click calls document.startViewTransition(() => render(next)). What happens to the first two transitions and their callbacks, and which promise should you use to run cleanup that must happen whether or not the animation played?
Show answer
Each new call skips the transition before it, so the first and second transitions end early with their animations jumping to the finish. Their update callbacks still run, so all three renders happen and the page reaches the final state. For cleanup, use transition.finished with .finally(). It settles whether the transition was animated or skipped. ready would reject on a skip.
Exercise
Your callback is async () => { const data = await fetch('/item').then(r => r.json()); render(data); } and the page feels frozen for a second on slow networks. Why, and how do you fix it?
Show answer
The browser pauses rendering after capturing the old state and resumes only when the callback's promise settles, so the slow fetch freezes the page. Fetch the data before calling startViewTransition(), then make the callback do only the synchronous render(data).