Sub topic 14
Performance and common pitfalls
This chapter assumes you know how to opt in with @view-transition, how the pseudo-element tree works, and how view-transition-name matches elements across pages. It covers what makes transitions slow and the mistakes that stop them from running.
Where the time goes
A cross-document transition adds work to every navigation. The browser captures the old page, loads the new one, captures it, and then animates the snapshots on the compositor. Two things matter for speed:
- Snapshots are textures. Each named element adds one more texture to hold and animate.
- The transition cannot start until the new page can render. A slow server response or a slow first render delays the animation directly.
The browser also skips the transition if the new page takes too long to become renderable. A skipped transition is not an error. The user simply gets a normal navigation.
Keep the number of named elements small
Every element with a view-transition-name gets its own group, old snapshot, and new snapshot. A product grid with 60 named thumbnails creates 60 groups. That can cause dropped frames on mid-range phones.
Name only what the user needs to track. For a list-to-detail navigation, that is one element, the thumbnail that was clicked. This is why the pageswap and pagereveal handlers from the earlier chapter set the name dynamically.
Pitfall: duplicate names
Names must be unique within a page. If two elements share one name at capture time, the transition is skipped. This often happens when you put view-transition-name: post-image in a stylesheet and the list page renders many cards.
/* Wrong: every card gets the same name, so the transition is skipped. */
.card img {
view-transition-name: post-image;
}Set the name from JavaScript on the one clicked card instead, as in the pageswap example. If you do need static names, generate a unique one per item, for example with an inline style attribute.
Pitfall: missing opt-in on one page
Both the old and the new page must contain @view-transition { navigation: auto; }. If you add it to the list page only, the post page never takes part. When a transition does not run, check this first.
Pitfall: animating the wrong thing
The snapshots are images, so animating opacity and transform is cheap. Animating filter, clip-path, or large blur effects on full-page snapshots costs more. Keep durations short. Around 200 to 300 ms is enough for most page changes, and long animations make the site feel slow even when the network is fast.
Pitfall: stale names after going back
A name set from JavaScript stays on the element. If the page is restored from the back/forward cache, an old name can remain and collide with a new one. Clear names after the transition finishes, as the pagereveal example does with await event.viewTransition.finished.
Pitfall: transitions that hide slow pages
A transition does not make a page load faster. It can make a slow load more noticeable, because the old page stays frozen while the new one loads. Use render blocking (<link rel="expect">) only for content the animation truly needs. Blocking on a large part of the page delays first paint for everyone.
Quick checklist
| Symptom | Likely cause | Fix |
|---|---|---|
| No animation at all | Missing opt-in on one page, or a cross-origin navigation | Add the `@view-transition` rule to both pages and check the origins |
| Plain page load, no morph | Duplicate `view-transition-name` | Name only one element per page |
| Janky animation | Too many named elements or expensive properties | Reduce names and animate `opacity` and `transform` |
| Animation to a half-loaded page | New page rendered too early | Add `rel="expect"` for the critical element |
| Motion for users who disable it | No reduced-motion rule | Add the `prefers-reduced-motion` media query |
Exercise
A list page shows 40 cards, each with .card img { view-transition-name: post-image; }. Clicking a card gives a normal page load with no animation, and the opt-in rule is present on both pages. What is wrong, and how do you fix it?
Show answer
All 40 images share the same name, and names must be unique, so the browser skips the transition. Remove the static rule. In a pageswap handler, set view-transition-name: post-image on only the clicked card's image, and in pagereveal set it on the matching thumbnail when returning to the list, clearing it after viewTransition.finished.