You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Compositions can't measure text or layout: no document, no canvas measureText, no geometry on refs #54
From #13 (@kevinschaich): a composition can't measure its text or layout before it draws, and many motion components rely on that. We ran snapcn's 61 free components (MIT) through raea; 27 of them measure, in one of two ways, and both fail:
1. Canvas text measurement and fonts: there is no document in a composition.
document.createElement("canvas").getContext("2d").measureText(...) throws "Can't find variable: document". This crashes bloom-lockup, hello-zoom, sky-lockup, spec-sweep and title-sweep.
document.fonts.ready and document.fonts.load aren't there either.
Components that guard with typeof document fall back to guessed widths, so their layout drifts from Chrome. In word-gather, every word sits a little off.
2. Layout reads on refs: a ref's element has no geometry and no DOM API.
An element from useRef, read in useEffect, has offsetWidth, offsetHeight, offsetLeft and offsetTop undefined.
It has no getBoundingClientRect(), children, querySelectorAll() or style.
This crashes karaoke-captions and word-captions (getBoundingClientRect is not a function), text-reveal (NaN from offsetWidth), text-rewrite (querySelectorAll), type-morph ([...el.children]) and search-typing (el.style).
Chrome logs 335 function. raea logs undefined undefined, and document is undefined.
These components measure in an effect while the first frame is held (delayRender/continueRender), so they expect the read to be synchronous and the measured frame to be the one that's captured. An app page in raea (@raea/ui's DOM) already has all of these: geometry from the host's layout, children, querySelectorAll, and a canvas 2D context with measureText. A composition's elements come from bevy-react's bridge, which has none of them.
Fixed on main for 0.1.2. A composition's refs, document and window now answer from the same layout that draws the frame, synchronously: getBoundingClientRect (through transforms and perspective), offsetWidth/offsetHeight and the rest, getComputedStyle, children and selectors, document.createElement, createRange, document.fonts, ResizeObserver, a canvas's measureText with the real fonts, and svg text lengths. delayRender/continueRender hold a frame until a measure lands, and the reads work in live play too.
Your repro (the probe in bench/layout-reads/probes) now puts "here" at x 342, where Chrome puts it.
Measured against headless Chrome (same fonts, deviceScaleFactor 1, every text run's box and ink within 1 px at the first, middle and last frames) on snapcn's 33 measuring components:
before: 3 of 33 pass
now: 23 of 33 pass
The 10 still off, each with its cause, are listed in docs/layout-reads.feature (LR10): mostly a few pixels of ink through transforms, and SF's tracking table on the canvas.
Cost: a composition that reads nothing renders the same frames in the same time (P26 unchanged). Over 300 frames, the first read in a frame costs about 0.39 ms, and each further read in that frame about 0.01 ms.
The manual's new guide, "Web components that measure" (docs/manual/guides/web-components.md), lists what answers and what doesn't yet (no innerHTML, a Range across wrapped lines is one rect, MutationObserver and IntersectionObserver never call back).
Activity
LR0: Layout reads, the plan (docs/layout-reads.feature): compositions…
LR0: bench/layout-reads, compositions that measure their text and lay…
LR1: A composition reads its layout synchronously from the page that …
LR3: a composition's refs have the geometry a web component reads, fr…
LR11: where the docs stand (the manual's web-components guide, raea-s…
LR2: every host that runs a composition answers its layout reads. Liv…
shinyobjectz commentedon Nov 13, 2026
Fixed on main for 0.1.2. A composition's refs,
documentandwindownow answer from the same layout that draws the frame, synchronously:getBoundingClientRect(through transforms and perspective),offsetWidth/offsetHeightand the rest,getComputedStyle, children and selectors,document.createElement,createRange,document.fonts,ResizeObserver, a canvas'smeasureTextwith the real fonts, and svg text lengths.delayRender/continueRenderhold a frame until a measure lands, and the reads work in live play too.Your repro (the probe in
bench/layout-reads/probes) now puts "here" at x 342, where Chrome puts it.Measured against headless Chrome (same fonts, deviceScaleFactor 1, every text run's box and ink within 1 px at the first, middle and last frames) on snapcn's 33 measuring components:
The 10 still off, each with its cause, are listed in
docs/layout-reads.feature(LR10): mostly a few pixels of ink through transforms, and SF's tracking table on the canvas.Cost: a composition that reads nothing renders the same frames in the same time (P26 unchanged). Over 300 frames, the first read in a frame costs about 0.39 ms, and each further read in that frame about 0.01 ms.
The manual's new guide, "Web components that measure" (
docs/manual/guides/web-components.md), lists what answers and what doesn't yet (noinnerHTML, a Range across wrapped lines is one rect, MutationObserver and IntersectionObserver never call back).LR10, LR11: done. LR0 lists the gap left after LR1-LR10 (23 of 33 pas…