Scoped View Transitions for Firefox

Bugzilla: bug 2075158 (meta) Phabricator: patch stack in preparation css-view-transitions-2 pref: dom.viewTransitions.scoped.enabled

CSS View Transitions Level 2 adds Element.startViewTransition(): a view transition scoped to one element instead of the whole document. The pseudo-element tree (::view-transition, ::view-transition-group(), ...) is generated on the scope element, only its subtree participates, and the rest of the page keeps running -- including other scoped transitions at the same time.

const transition = card.startViewTransition(() => updateCard());
await transition.finished;
90/93scoped tests pass, wpt upstream rev 536ae94
80/81scoped tests pass, vendored snapshot
0unexpected results in css/css-view-transitions/
1pref, default off

90/93 is this build on the current upstream suite (wpt rev 536ae94, 77 tests + 16 crashtests), the same revision the WebKit sampler reports against. The 3 failures: the mathml scope root (needs display: math, bug 1664261), occlusion with an opacity: 0 scope (needs IntersectionObserver v2, bug 1896900), and display-change-during-transition.html, where the test's :not(:only-child) qualifier contradicts the spec's pseudo-tree :only-child matching once auto-nesting re-parents the group (a wpt fix is in flight; with it the score is 91/93). Fixed since the last capture: svg and replaced scope roots, negative playback rate, view-transition-name: auto (bug 1918218), auto-nesting per csswg-drafts #13420, and the tentative startViewTransition({ shadowRoots }) option (all 8 tests). Also fixed: concurrent scoped transitions no longer swap each other's group keyframes (two transitions sharing a name like root resolved the first transition's captured geometry, visibly resizing the other scope's snapshot mid-animation; visible in the previous capture of the clip demo). 80/81 is the wpt snapshot vendored in firefox-main, the number the in-tree CI runs enforce.

Before / after

Same build, same demo page, screenshot taken mid-transition with every animation parked at 50% (animation-play-state: paused plus a negative animation-delay). Before (pref off, the shipping behavior today): the DOM mutation applies instantly, there is nothing to animate. After: tiles morph inside the scope while the spinner and ticker outside the scope keep running -- parked at the same angle in both captures, so the only difference is the transition itself.

before -- no Element.startViewTransition, instant swappref off
before: end state applied instantly
after -- mid-transition, scope morphing, outside livepref on
after: tiles cross-fading and morphing
before -- clipping/overflow demo, instant swappref off
before: end state, no transition
after -- escape past the scope, clipped by the ancestor, scroll stays 0,0pref on
after: group outside scope bounds, cut at ancestor clip

Video

The same transition as video: a full cycle (forward transition, settle, reverse transition) assembled from 62 per-frame captures of the same build with the pref on (animations stepped through animation-delay, 1.5s duration each way). The before video is the pref-off behavior: a few frames of the old state, then an instant swap in each direction.

before -- instant swappref off
after -- scoped morph, forward + reverse cyclepref on

A second capture page exercises the clipping and overflow rules: the pseudo tree escapes the scope's own bounds but stays clipped by an ancestor overflow: hidden, and a scope with overflow: auto gains no scroll range from the overlay.

before -- instant swappref off
after -- escape + ancestor clip, no scroll rangepref on

Live sampler

Element-scoped morph · card.startViewTransition(mutate)
A
B
C
D
before
after
Four named tiles re-grid inside the scope. With the pref on the old and new snapshots cross-fade and the groups morph between the two layouts; without it the mutation applies instantly (the Rendered tab falls back to that).
Scope inside a shadow root · adopted stylesheet styles the pseudos
before
after
The scope lives inside a shadow root and its view-transition-name comes from an adopted stylesheet. The dynamic ::view-transition styles resolve in the shadow root's style scope, so the part morphs from square to circle across the card.
Scope clip escaped, ancestor clip applied
VT
scope
before
after
The tile flies beyond the green scope bounds -- the pseudo tree escapes the scope's own clip -- but the dashed amber ancestor with overflow: hidden still cuts it at the edge. Mid-flight the circle is visibly outside the scope and clipped by the ancestor.
Overlay adds no scrollable overflow to the scope
VT
scroll 0,0
before
after
The scope has overflow: auto with styled (non-overlay) scrollbars. The flying group leaves the content box during the morph, yet no scrollbars appear and scrollLeft/scrollTop stay 0,0: the overlay is excluded from the scope's scrollable overflow.

What is in the patch stack

One feature-flagged implementation pass, developed as a 12-commit branch on top of firefox-main and being split into Phabricator revisions under bug 2075158: the Element.startViewTransition() API and scoped lifecycle, the pseudo-element tree on arbitrary scope elements, the snapshot containing block and its layout (no scrollable-overflow contribution to the scope), clip escape past the scope with ancestor clips still applied, scoped capture and paint order, dynamic UA styles resolved in the scope's (possibly shadow) style scope, concurrent scoped transitions, hit testing over the overlay, devtools animation metadata, and UA-sheet parsing of the new pseudos with the pref off.

Result

beforeafter
wpt css/css-view-transitions/scoped (81 tests, vendored snapshot)suite skipped, 0 passing80 of 81 pass, 63 of 66 subtests; 1 known failure needs view-transition-name: auto
full css-view-transitions suiteas expectedas expected, 0 unexpected results, no document-transition regressions
wpt scoped suite at upstream rev 536ae94 (93 tests)suite skipped, 0 passing90 of 93, including the 8 tentative shadowRoots-option tests; remaining failures are two platform gaps (display: math, IntersectionObserver v2) and an upstream test bug
WebKit implementation (PR #81741, same suite rev)87 of 93 at the same wpt revision: WebKit implements the tentative shadowRoots option, Gecko passes scoped cases WebKit still misses. The WebKit sampler runs the same four cases with the same capture recipe: two independent implementations, same output.
Commands behind the numbers and captures
# test counts (CI reftests are not headless, so neither is this)
xvfb-run -a ./mach wpt testing/web-platform/tests/css/css-view-transitions/scoped --log-raw scoped.log
xvfb-run -a ./mach wpt testing/web-platform/tests/css/css-view-transitions --log-raw all.log

# 90/93: overlay the 16 files added upstream since the vendored snapshot
# (github.com/web-platform-tests/wpt rev 536ae94) into the working tree,
# re-run the directory with --manifest-update, score wpt.fyi-style
# (test passes if PASS, or OK with zero failing subtests), restore the tree

# captures: same build, marionette drives a capture page that parks every
# animation at frame t/24 via animation-play-state: paused and a negative
# animation-delay; the pref is the only variable between before and after
xvfb-run -a ./mach python capture.py   # obj-debug/dist/bin/firefox, 800x600, ffmpeg x11grab

# videos from the 25 per-frame captures
ffmpeg -framerate 16 -i after-%02d.png -c:v libx264 -pix_fmt yuv420p after-main.mp4
ffmpeg -framerate 16 -i after-%02d.png -vf format=yuv420p -c:v libvpx-vp9 -b:v 0 -crf 32 after-main.webm