v160 · javascript · cssom · view transitions
View transition disambiguation
The motivating case from the ChromeStatus entry. A real document.startViewTransition() shuffles three cards, each with its own view-transition-name — one of them, 1st-pick, only expressible escaped as \31 st-pick. While it runs, the page collects each ::view-transition-group() as a CSSPseudoElement. All three report the same type. Only selectorText says which card each object is — and the page uses it to spotlight one group by dimming the others, driven purely by the objects.
chrome://flags/#enable-experimental-web-platform-features and relaunch, or launch with --enable-blink-features=CSSPseudoElementSelectorText / --enable-features=CSSPseudoElementSelectorText. Until then the spotlight runs in a clearly labelled fallback mode that keys animations on names the page already knew — not on anything read from the objects.
| name | type | selectorText | KeyframeEffect.pseudoElement | pseudo(that string) |
|---|---|---|---|---|
| no transition run yet | ||||
the composition
const t = document.startViewTransition(shuffle);
await t.ready;
const html = document.documentElement;
const groups = names.map((n) => html.pseudo(`::view-transition-group(${CSS.escape(n)})`));
groups.map((g) => g.type); // ["::view-transition-group", × 3] — indistinguishable
groups.map((g) => g.selectorText); // ["…(alpha)", "…(beta)", "…(\\31 st-pick)"]
for (const g of groups)
if (g.selectorText !== spotlight.selectorText)
html.animate({ opacity: [1, 0.25, 1] },
{ duration: 900, pseudoElement: g.selectorText });
Edge case worth knowing: the animations the browser creates report effect.pseudoElement as "::view-transition-group(1st-pick)" — unescaped — which is not a valid selector (an identifier cannot start with a digit), so html.pseudo() rejects it. selectorText serializes the ident with escaping (Chromium’s SerializeIdentifier), so it always round-trips.