Sub topic 16
Debugging transitions in DevTools
This chapter assumes you can already wrap an update in document.startViewTransition(). It also assumes you know the ::view-transition pseudo-element tree, view-transition-name, and the three ViewTransition promises. It uses Chrome DevTools in the examples. Other Chromium-based browsers behave the same way, and Firefox and Safari have their own inspectors.
Why transitions are hard to debug
A view transition usually lasts a fraction of a second. The pseudo-elements you want to inspect exist only while it runs, and they disappear when it finishes. If the transition is skipped, they never appear. Debugging therefore comes down to two jobs:
- Keep the transition alive long enough to look at it.
- Find out why it was skipped or looks wrong.
Freeze the transition in DevTools
Open the Animations panel (the three-dot menu, then More tools, then Animations). Trigger the transition. The panel records the animations that run on the view-transition pseudo-elements. You can then do three things:
- Pause the animation group so the pseudo-element tree stays in the DOM.
- Drag the playhead to scrub through the animation frame by frame.
- Set a slower playback rate, such as 10%, and replay it.
While the animations are paused, the Elements panel shows the tree at the end of the <html> element. Select any node and its computed styles appear in the Styles pane, so you can edit animation-duration or mix-blend-mode live.
You can also freeze the transition from code. This helper pauses only the view-transition animations and leaves the rest of the page alone.
async function freezeTransition(transition) {
try {
await transition.ready;
} catch (error) {
console.warn('Transition was skipped, nothing to freeze:', error);
return;
}
for (const animation of document.getAnimations()) {
const pseudo = animation.effect?.pseudoElement ?? '';
if (pseudo.startsWith('::view-transition')) {
animation.pause();
}
}
}
document.addEventListener('click', () => {
if (!document.startViewTransition) return;
const transition = document.startViewTransition(() => {
document.body.classList.toggle('alt');
});
freezeTransition(transition);
});Call animation.play() on the same set of animations to resume. Remove the helper before shipping.
A second option is to slow everything down with CSS while you work.
::view-transition-group(*),
::view-transition-old(*),
::view-transition-new(*) {
animation-duration: 5s !important;
}The !important is needed because your own rules and the browser's default rules both set durations.
Read the pseudo-element tree
The frozen tree has this shape:
::view-transition
└─ ::view-transition-group(root)
└─ ::view-transition-image-pair(root)
├─ ::view-transition-old(root)
└─ ::view-transition-new(root)Each element with a view-transition-name adds another group beside root. Look for these things:
- Missing groups. If the group for
herois not in the tree, the name was not applied in the old state, the new state, or both. A group with only an old or only a new image is normal for elements that appear or disappear. It then fades instead of morphing. - Group size and position. The group animates
width,height, andtransformfrom the old box to the new box. A wrong box means the element's layout was not what you expected at capture time. - Aspect ratio changes. If the old and new images have different aspect ratios, the snapshots look stretched. The usual fix is
height: 100%; width: auto; object-fit: coveron::view-transition-old(name)and::view-transition-new(name).
Log the promises
The three promises tell you which phase failed. This helper logs each one.
function debugTransition(transition, label = 'transition') {
transition.updateCallbackDone.then(
() => console.log(`${label}: DOM update done`),
(error) => console.error(`${label}: update callback threw`, error)
);
transition.ready.then(
() => console.log(`${label}: ready, animations started`),
(error) => console.warn(`${label}: skipped (${error.name})`, error.message)
);
transition.finished.then(
() => console.log(`${label}: finished`),
() => console.error(`${label}: finished with an error`)
);
return transition;
}
debugTransition(
document.startViewTransition(() => updateView()),
'nav'
);Read the output like this:
update callback threwmeans your DOM update failed. The transition is skipped, and the page may be in a half-updated state. Fix the callback first.skipped (InvalidStateError)means the browser could not run the animation. The DOM update still happened. The cause is usually a duplicate name, which the browser also logs to the console.skipped (AbortError)means a newer transition replaced this one, orskipTransition()was called.readyfollowed by no visible motion means the transition ran but your CSS cancelled or hid it. Check foranimation: nonerules, a reduced-motion rule that applies on your machine, or anopacityof 0.
Find duplicate names
Two elements with the same view-transition-name that are both rendered in the same state make the browser skip the transition. This often happens in lists, where every card gets hero. The helper below finds such names in the current DOM.
function findDuplicateNames(root = document) {
const byName = new Map();
for (const element of root.querySelectorAll('*')) {
const name = getComputedStyle(element).viewTransitionName;
if (!name || ['none', 'auto', 'match-element'].includes(name)) continue;
byName.set(name, [...(byName.get(name) ?? []), element]);
}
return [...byName].filter(([, elements]) => elements.length > 1);
}
console.table(
findDuplicateNames().map(([name, elements]) => ({ name, count: elements.length }))
);Run it in the console right before the transition starts, and again inside the update callback after the DOM changes. Both the old and the new state must be free of duplicates. The fix is to name only the element that is moving, as the shared-element chapter did, or to generate a unique name per item.
Common failures and their causes
| Symptom | Likely cause | What to check |
|---|---|---|
| No animation, page updates instantly | API unsupported, or `prefers-reduced-motion` rule applies | `document.startViewTransition` exists; your OS motion setting |
| Console warns about a duplicate name | Same name on two rendered elements | `findDuplicateNames()` in each state |
| Element fades instead of moving | Name missing in the old or the new state | Group in the frozen tree has only one image |
| Element jumps, then animates | Name was set after the old snapshot was taken | Set the name before calling `startViewTransition()` |
| Animation looks stretched | Old and new aspect ratios differ | `object-fit` on the image pseudo-elements |
| Element draws above or below others unexpectedly | Named elements are painted in a separate layer | Group order in the tree follows DOM order |
| Clicks do nothing during the transition | The overlay receives pointer events | Expected; keep transitions short |
Stacking and clipping surprises
An element with a view-transition-name becomes its own stacking context while the capture happens. During the animation, its snapshot is painted in the transition overlay, above the rest of the page. Two consequences follow:
- Ancestors with
overflow: hiddenorborder-radiusdo not clip the snapshot while it moves. A card that was clipped inside a scrolling list can appear to burst out of it. Addoverflow: clipand a matchingborder-radiuson::view-transition-group(name)to restore the clipping. - Named elements are layered in DOM order, not in the visual order you expect from
z-index. If one hero should sit above another, change the DOM order or the names you assign.
A debugging checklist
The diagram summarizes the order in which to check things.
Start with the promises, because they separate "never ran" from "ran badly". Then freeze the tree and edit the CSS live until the motion is right. Copy the working values back into your stylesheet.
Exercise
A click handler calls document.startViewTransition() and the page content changes with no animation. The console shows no errors from your code, and transition.ready rejects with InvalidStateError. What is the most likely cause, and what two steps would confirm and fix it?
Show answer
Two rendered elements most likely share the same view-transition-name, so the browser skipped the animation. The DOM update still ran, which is why the content changed. To confirm, run a duplicate-name check such as findDuplicateNames() in the old state and again inside the update callback, and read the console warning that names the duplicate. To fix it, name only the element that moves, or give each item a unique name, and clear the name from the old element when the new one takes it.