Blog · Frontend · · 2 min read
Removing :has() and counting transition events
Early versions of Ptree drove whole-page state with root-anchored :has() rules and called getAnimations() to tell when a navigation hop had settled. Chrome profiles showed both burning hundreds of milliseconds per interaction. Moving state onto container classes and counting native transition events cut frame times roughly fivefold.
State written down from a shared container
Native checkboxes hold Ptree’s filter, location, common-name, and panel states. Reading those controls from near the root with :has(#filter:checked) or :has(#location:indeterminate) removed a few event listeners, but in Blink a :has() anchor near the document root causes every DOM insertion, class change, or title write below it to trigger broad style invalidation. Dragging a filter thumb or inserting a silhouette icon forced Chrome to restyle far more of the tree than had changed.
Every viewer stylesheet now contains zero :has() rules. When a control’s state is read by multiple regions, its change listener toggles one class on the nearest container those regions share, documented directly above the element:
<!-- toggled classes: Common, Filtering, Picking, Located -->
<body class="Common" data-1p-ignore>
Descendants below <body>, <article>, or <section> match plain class selectors that Blink invalidates locally.
Counting structural transitions
After a multi-step tree navigation finishes moving tiles and columns, the view reaps .leaving nodes and hands the camera’s displacement back to native scrolling. Measuring bounding boxes and calling document.getAnimations() after each step cost Chrome about 118 ms in forced layout reads and 146 ms in animation queries on a single hop. Under prefers-reduced-motion, settling took 1.1 to 1.6 seconds.
The shared View class now listens to transitionrun, transitionend, and transitioncancel on <main> and maintains one counter (_flying) filtered to structural geometry properties:
const MOTION = new Set([
"translate", "transform", "opacity", "d",
"fill-opacity", "display", "visibility",
]);
Color transitions, hover washes, and label fades are excluded so the view rests while paint finishes. Because a transition created in one frame is announced at the start of the next, and a retargeting arrives as a cancel and a run in one batch, rest is a frame where _flying is zero, taken at least one frame after the write.
One marker for every map
Location picking had a parallel invalidation problem: writing the chosen point’s coordinates into custom properties on :root forced a document-wide restyle on every click. Moving those coordinates onto the x and y attributes of a single #point <svg> symbol, drawn into every range map via <use>, confined the update to the maps alone.
Measured in Chrome
All three changes shipped together in the November 9, 2026 release and were timed directly in Chrome:
- Navigation hops dropped 118 ms of layout reads and 146 ms of animation queries to zero; reduced-motion hops fell from 1.1–1.6 s to 300–600 ms.
- Tree glides fell from 186 ms at the 90th percentile to 25–42 ms once hidden paint snapped instead of transitioning.
- Splitter drag samples fell from 150 ms to 35–98 ms.
- Location picks fell from 190 ms to 16 ms.
- Legend brushes dropped to a single restyle pass.