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.

Probing this browser…
Aalpha
Bbeta
11st-pick
Spotlight during the transition
::view-transition-group objects captured in transition.ready
nametypeselectorTextKeyframeEffect.pseudoElementpseudo(that string)
no transition run yet
Press shuffle.

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.

see also