Skip to content

perf: one flex engine, flex text measured before the frame, draw order follows children (1.8 streams L, T, N) - #89

Merged
chiefcll merged 34 commits into
mainfrom
perf/streams-l-t-n
Nov 20, 2026
Merged

chiefcll merged 34 commits into
mainfrom
perf/streams-l-t-n

Conversation

@chiefcll

Copy link
Copy Markdown
Contributor

Ports three streams of the 1.8 branch onto main: L (flex and layout queue), T (text measurement) and N (nodes, plus the follow-up N3). The commits are cherry-picked with -x, so each one names its 1.8 original. Streams M, F, P and S, and the final fix wave, are not included.

What's in it

Stream L: one flex engine and a depth-ordered layout queue

  • src/core/flex.ts and VITE_USE_NEW_FLEX are gone. Every build runs flexLayout.ts, which no longer allocates per layout pass and writes only the values that changed.
  • Layout runs from a queue ordered by depth, deepest container first, each at most once per pass. The post-mutation pass is a microtask only.
  • Flex fixes B5–B12 (see below).

Stream T: Solid measures flex text with TextNode.measure()

  • A <text> whose parent lays out (flex or onLayout) is measured in Solid's post-mutation pass, before the frame. That takes one walk, with no wait for loaded.
  • New src/core/fontLoaded.ts keeps a list of texts waiting on a font. The DOM renderer gains measure().
  • Uses renderer 2.0.7's TextNode.measure() and layout cache, which are already published, so no renderer release is needed.

Stream N: prop accessors, handle hygiene, child list and draw order

  • One accessor per forwarded prop, with a constant name.
  • B20: unknown names are never written to a renderer v2 handle.
  • B19: draw order follows children order, using Node.insertBefore. The DOM renderer gets insertBefore too.
  • N3: a removed node keeps its parent link, as in 1.6, and does not lay out its old parent.

Behaviour changes for apps

  • Apps that did not set VITE_USE_NEW_FLEX now get the CSS-aligned engine. Where the two engines differed:
    • a number padding also offsets the cross axis;
    • padding arrays, paddingTop / paddingRight / paddingBottom / paddingLeft and margin arrays work;
    • wrapped lines start at the cross padding;
    • flexShrink and flexBasis take effect.
  • B5: an unsized <text flexItem={false}> no longer blocks its container's layout.
  • B6: justifyContent="center" with padding centres inside the padding.
  • B7: cross-axis center and flexEnd stay inside the cross padding.
  • B8: a flexGrow item is sized from its own size on every layout.
  • B9: a wrapping container with no cross size puts wrapped items on their own lines.
  • B10: wrap-reverse wraps.
  • B11: a contain text subtracts its right and bottom margins.
  • B12: maxLines={1} with a lineHeight of 3 or less is read as a multiplier.
  • Layout timing:
    • Flex text is laid out before the frame, including under alpha-0 or out-of-bounds ancestors (decision 5.2).
    • A loaded that leaves the size unchanged lays nothing out.
    • A flexGrow container calls onLayout once per layout.
  • B19: overlapping siblings with equal zIndex draw in children order after every update: a <Show> between siblings, <For> reorders, Virtual window shifts. A child inserted before itself now stays in place, where 1.6 appended it.
  • B20:
    • Text-only props written to a <view> stay on the ElementNode and don't reach view.lng.
    • Writes to absX, absY and destroyed are ignored; on renderer v2 they used to throw.

Conflicts resolved against main

  • atlasGroup (feat: renderer 2.0.7, pass atlasGroup through to the renderer node #79): it was in the old forwarded-prop list, so it now has its own accessor in N's per-prop form.
  • removeItem (main's splice-free child list from perf: remove per-press allocations (no functional change) #71): B19's rewrite of insertChild and removeChild replaces it, so it's deleted. tests/childList.test.ts now expects the B19 "before itself stays in place" result.
  • DOM renderer destroyed: main's field, which marks the whole subtree at destroy (fix(focus): skip destroyed elements in restoreFocus #69, used by restoreFocus), is kept. 1.8's get destroyed() duplicated it and is dropped.
  • withScrolling: N's guard for a parent-less Row/Column is applied to main's restructured code.
  • Skipped as already on main: the two B17 commits and "TextNode assigns its fields in the constructor".
  • Docs: docs/flow/layout.md takes 1.8's single-engine text, with "1.7" changed to "1.8". MIGRATION-1.7.md is not brought over; the list above stands in for it.

Testing

  • npm run tsc, npm run lint and npm run build pass.
  • npm run test:webgl: 38 of 38 pass on the real renderer.
  • npm test: 728 passed and 14 failed. The 14 are the same contract-nodes and contract-styles animation and transition cases that fail on main (main: 14 failed, 743 passed). They are timing-sensitive: on both branches they pass in some runs and fail in others. flex.performance.spec.ts also fails some runs under full-suite load, and passes on its own.
  • The test count drops because the two-engine flex cases are gone.
  • Not checked on a device or in the demo app.

🤖 Generated with Claude Code

chiefcll and others added 30 commits November 19, 2026 14:51
Keep src/core/flexLayout.ts (what the demo app runs) and delete flex.ts
and the VITE_USE_NEW_FLEX switch (decision 5.3). The engine now:

- allocates nothing per pass: per-child values live in module-level
  typed arrays grown on demand (Float64Array: positions no longer carry
  float32 rounding), children are reached through a reused index array,
  sorted by flexOrder (stable insertion sort) only when a child has one,
  and the cross alignment closure is a plain function;
- writes x, y, width and height only when the value changes, so a
  relayout that moves nothing writes nothing;
- no longer has flex.ts's production console.warn.

Bug fixes (design 5.8), each pinned in contract-flex.test.tsx:
- B5: a child with flexItem={false} is skipped before the text check, so
  an unsized text badge no longer blocks its container.
- B6: justifyContent center centres inside the padded box.
- B7: cross-axis center/flexEnd align inside the padded box (and, with
  wrap, inside the line) instead of offsetting the full size by
  paddingTop.
- B8: flexGrow starts from the item's own size on every pass (the grown
  size and the size before it are recorded on the item); an item no
  longer grown goes back to its own size.
- B9: wrapped items are placed on their line when the container has no
  height.
- B10: wrap-reverse wraps, with the first line at the end.

contract-flex.test.tsx runs its table once, on the one engine; where
flex.ts gave a different result the case keeps it in a comment (what
changes for apps on the default build). The flex specs run flexLayout.ts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 23e9f94)
…ineHeight multiplier

In render()'s text path (design 5.8):
- B11: `contain` without a size subtracts marginRight/marginBottom read
  from the ElementNode. They were read from the renderer props bag,
  where margins are never stored, so the subtraction was always 0.
- B12: `maxLines={1}` resolves a lineHeight at or below 3 (a multiplier,
  as the renderer reads it) as lineHeight * fontSize. maxHeight was the
  bare multiplier (1.2 px), so such a text was 1.2 px high in flex.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 59ab929)
…rotask

The layout queue (design 3.4.4, 3.5):
- Containers are bucketed by depth (computed once when queued) and laid
  out deepest first, so within one post-mutation pass each container runs
  at most once unless a child's size changed after its run. No copy of
  the queue per run: the buckets keep their capacity, and a node carries
  a `_layoutQueued` flag that updateLayout() clears.
- queueLayout(node) replaces addToLayoutQueue; a container queues its
  parent only when its own size changed (and the parent lays out).
- A flexGrow container re-runs its flex children once per pass and runs
  again only if one of them resized (was: every other pass, and always
  twice).
- The delete-flush keeps its array's capacity instead of resetting it.

Scheduling:
- schedulePostMutation queues the microtask only. It no longer also
  registers reprocessUpdates, whose in-frame run was a no-op that still
  requested a frame.
- schedulePostMutationInFrame() also registers reprocessUpdates, for
  handlers the renderer calls between its walks. _layoutOnLoad's `loaded`
  handler uses it: it queues the parent instead of laying it out
  synchronously (several loads in a frame cost one pass), and does
  nothing when the node's size is unchanged.

tests/layoutQueue.test.tsx pins one pass per affected container in a
3-level nested flex press, deepest first, the unchanged-size skip and the
scheduling. contract-text.test.tsx: the autosize pin now waits for the
pass, and text-change tests wait a macrotask (the re-measure's microtask
and the pass's).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 31e6c78)
The first flex commit aligned wrapped items against their line, which
moved items in a wrapping container with a height and alignItems center
or flexEnd even without padding (5px in the demo app's Flex page): a
change no approved fix covers. Wrapped items align as before 1.7 again,
from their line's start against the container's cross size, with only
the approved changes: that size less the cross padding (B7), the line
size when the container has no cross size (B9, previously unplaced), and
mirrored lines for wrap-reverse (B10). A table case pins the unchanged
result against the original engine.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 01d5fa1)
Review fixes for the flex engine:

- Compare-before-write read the current value, which with a transition
  is the animated one, not the target. A node moved A -> T by one layout
  and back to A by the next, before the animation advanced, read A and
  was not written, so it ended at T. With a transition on the prop the
  engine now also keeps the last value it wrote (`_flexX`, `_flexY`,
  `_flexW`, `_flexH`) and skips only when both the read and that value
  match; without one, the read alone decides (the renderer ignores an
  equal write anyway). This covers the container's own size writes too.
- B8 with a width transition: the read is the animated width, so the
  flexGrow record is kept as it is instead of being taken for a size the
  app wrote.
- A pass started while another runs (an app callback that a write fires,
  e.g. onAnimation calling updateLayout) gets its own scratch arrays, so
  the outer pass's are intact when it resumes. Only the nested case
  allocates.
- Positions are computed into a scratch array and written by one loop
  (main then cross per child), so the writers stay small enough to be
  inlined and do not box their doubles; the child's alignment is resolved
  once in the collecting loop.
- getArrayValue is exported for the text `contain` margins.

contract-flex.test.tsx: the A -> T -> A case and the B8 mid-animation case
(DOM renderer, `animate` spied), a nested pass, and the 5.3 record for
flexShrink, flexBasis and a shrink-only container's flexBoundary, which
flex.ts did not handle. A comment on the B9 pin notes that wrapped
center/flexEnd alignment is not stable across passes (as before 1.7).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 57bb69a)
… delete flush

Review fixes for the layout queue and B11:

- A flexGrow container lays out its grown flex children again, then (if
  one resized) itself once more, all in the same updateLayout, and calls
  onLayout once, after that: the app sees the final layout, as the second
  of the two calls before 1.7 did. The first call, made before the
  children were laid out again, is gone.
- Delete flush: an entry is cleared (and its _queueDelete reset) before
  destroy(), and cleared entries are skipped, so an onDestroy that throws
  no longer makes every later post-mutation run throw before layout and
  focus. enqueueDelete always asks for the run.
- B11 reads the margin array too (marginRight || margin[1], as flex
  does).
- Doc comments: flexShrink/flexBasis are no longer "NEW flex layout"
  only.

Tests: the container's single onLayout after its children (spaceBetween
and content-fitting children), the margin array for `contain`, a deeper
container queued while a shallower one runs (one post-mutation run,
another sweep), `loaded` on a text removed from its container, and a
throwing onDestroy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 8513151)
57bb69a sent a node with any transition through out-of-line writers that
took their value from a typed array. Tiles with a scale transition (the
bench's virtual-grid) went through them for every position, and they
allocated about 5.3 KB per press there. setPos and writeSize now decide in
place: the transition check reads `c.transition` first, and the double is
only boxed on the write path. Same semantics; the tests are unchanged.

Bench alloc mode, arm C on renderer faf4b9f, bytes per op charged to the
flex function: virtual-grid 5,344 -> below the top 30 sites, virtual-row
1,797 -> 1,492, text-details-panel 1,774 -> 1,761.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 89a54f0)
A grown child that is itself a flex container sizing to its content was
shrunk to its content and grown back on every relayout of its parent
(widths 40, 300, 40, 300 over two relayouts, plus two extra passes each):
every pass that grew set `_containsFlexGrow`, so updateLayout laid the
child out again. The flag is now set only when the pass changed a child's
size; a relayout that changes none writes nothing and runs no extra pass.
The flexGrow record is written only when it changes.

The size writers are called only when `current !== v` or the node has a
transition, so the common no-write case passes no doubles to a call.

contract-flex.test.tsx: restores the four Phase 1 onLayout contract
tests that 8513151 dropped by mistake (verbatim from 01d5fa1), and pins
two consecutive relayouts of the grown, content-sized child (no width
write, no pass of the child).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 08d7647)
57bb69a moved every position write into one loop over a scratch array
(and resolved alignment into codes). In the browser that charged more
boxing to the pass in text-details-panel (1,490 -> about 1,770 B per op)
than the earlier shape, so the per-justify loops and alignCross of
01d5fa1 are back, with the transition-aware setPos. The container size
writes keep their inline `current !== v || transition` test.

Bench alloc mode, arm C, renderer 6392ce4, bytes per op charged to the
flex pass (layout + alignCross): text-details-panel 1,496 (L2 1,490),
virtual-row 1,842 (L2 1,896), virtual-grid below the top 30 sites.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit a69c3b6)
Text-only props (fontSize, lineHeight, maxWidth, text, contain, ...) and
fontFamily (through fontWeight) written to an element that is not a
<text> became own fields of its renderer v2 handle. They now stay on the
ElementNode (`_textProps`, read back through the same accessors); a
<text> still forwards them to its renderer node. absX, absY and destroyed
leave the forwarded setter list: they are getter-only on v2, where a
write threw; the ElementNode ignores the write and keeps the getters.

The new WebGL test also writes every forwarded prop on a rendered node
and checks that the handle gets it under its own name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 7d40658)
…esign 3.6.6)

The forwarded props' getters and setters were made in loops, so each
shared one body (`this.lng[key]`, `this.lng[key] = v`): one inline cache
saw every prop name, a megamorphic keyed access, and into renderer v2's
prototype accessors a call V8 does not inline. They are written out, one
per prop, each loading or storing one constant name (no `new Function`,
which a TV app's CSP may forbid).

An animatable setter stores directly unless the node has a `transition`;
only then does `_sendToLightningAnimatable` run, and it returns whether
the write became an animation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit d33c789)
…table

With the setters no longer calling it, getPropertyAlias had one call
site, and terser (default compress options) inlined it there as an
IIFE: a closure allocated on every animated write (733 B per press in
virtual-row). The alias is written inline instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit a2666f2)
With `transition` on a rendered node, every animatable setter (the 25
node props, and fontSize/lineHeight on a <text>) must hand renderer v2's
animateProp its own name and the value, on its own handle, and not store
the value itself. animateProp is stubbed on Node.prototype. Passes on the
loop-made accessors (d342c37) and the written-out ones; a setter passing
another prop's name fails it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit ff1ad12)
bench/micro/accessors.test.tsx times 1.6 M reads and 400 k writes through
ElementNode's forwarded-prop accessors on 100 rendered views, in the
browser setup of vitest.webgl.config.ts (bench/micro/vitest.config.ts):

  npx vitest run --config=bench/micro/vitest.config.ts --reporter=verbose

Neither `npx vitest run` (excludes bench/) nor `pnpm test:webgl` (only
tests/webgl) runs it. M4 Pro, Chromium 141: loop-made accessors (d342c37)
about 16 ms read / 15 ms write, written out about 1.1 / 1.5 ms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 71fb38b)
DOMNode.insertBefore(child, before) makes `child` a child of the node
before `before` (null, or a node that is not a child, appends; a child
moves; a node placed before itself stays). It reorders the child's div
among the parent's divs, the DOM renderer's paint order among equal
z-index, and its place in the parent's `children` set. Typed on
IRendererNodeShaded. Solid uses it next for B19.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit d5db836)
…cans from the front

Renderer v2 draws siblings in its child order (among equal zIndex), but
insertChild never moved a renderer node: a node inserted before an anchor
(a <Show> between siblings, a <For> adding in the middle) was drawn after
its later siblings, and a same-parent move (a <For> reorder) not at all.

- insertChild places a rendered child with the renderer's insertBefore
  (renderer R4) before the renderer node of its next rendered sibling,
  and skips a same-parent move that leaves it there; solidOpts.insertNode
  places a node that render() just created (render appends it).
- insertChild, removeChild and getNextSibling find a node from the end
  (Solid appends and removes at the tail most often), checking the first
  child first, so Solid's cleanChildren (remove the first child until
  none is left) is O(n); inserts and removes no longer allocate (no
  splice, no rest array).
- removeChild clears the child's parent, so a re-insert does not pay a
  full miss; insertNode now tells a re-insert by a parent or a pending
  delete, and replaceText on a detached text node only sets its text.

Tests: tests/webgl/drawOrder.test.tsx (renderer v2 children order) and
tests/drawOrder.test.tsx (DOM renderer div and child-set order, the child
list, a preserved node re-inserted, replaceText on a removed node).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit f611469)
Renderer v2 keeps siblings sorted by zIndex; when an anchor's zIndex is
not the child's, the child goes to the nearest sorted place, so among
equal-zIndex siblings its order can differ from `children`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 1c74a6d)
Solid universal's swap of adjacent items calls
insertNode(parent, y, getNextSibling(x)), which for neighbours is y
itself. insertChild took y out first, so the anchor was no longer a
child and y was appended: [head, a, x, y, b, tail] swapped to
[a, y, x, b] gave [head, a, x, b, tail, y], and the renderers followed.
A node placed before itself now stays (DOM semantics): the anchor
becomes its next sibling, and the drawn-sibling check skips the renderer
call. Also fixes the stale comment on the removal.

Tests: the adjacent swap with a later sibling (DOM and WebGL), and a
spy on the parent's insertBefore across no-op moves (none) and a real
one (one call).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 1b0acbe)
An unrendered parent that got already-rendered children (moved in) and
new ones reparented all the rendered ones right after createNode, then
rendered the new ones, which append: [n1, moved, n2] drew as
[moved, n1, n2]. The reparent now happens in the ordered child loop,
just before each child's render(). Also covers the re-keyed
_hasRenderedChildren (a rendered node moved into an unrendered parent
that renders later).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 7240927)
…y per move

As renderer v2's Node.insertBefore: a destroyed parent or child does
nothing (it re-appended a destroyed child's div), and a destroyed anchor
appends (its div is no longer the parent's, so div.insertBefore threw).
The anchored move reorders the children Set in place instead of
collecting the anchor and its followers in an array.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit a4fa11b)
removeChild now clears a removed node's parent, and withScrolling's
first scroll read `componentRef.parent!.clipping`: a Row or Column that
is itself a removed root, with focus still stranded in it, threw on its
first key press. The clipping end offset is skipped without a parent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit e6d6a96)
f611469 (N2) made removeChild clear the removed node's `parent`. The
demo port found that this changes focus semantics: when a focused
element's subtree is removed and nothing re-focuses, 1.6 keeps building
focus paths and bubbling keys and events up the stale parent chain, so a
key on a removed card's Row still reached the live Column (demo
#/complexflex); with the link cleared, the chain ended at the removed
Row. Removed nodes keep `parent` again.

The re-insert fast path stays without it: removeChild marks an element
`_detached` (cleared by insertChild), so a removed element re-inserted
is not looked for in its old parent's children (no full-scan miss), a
same-parent re-insert is always placed in the renderer, and
getNextSibling answers undefined at once. insertNode is back to 1.6's
"had a parent" re-insert test.

New contract test (contract-focus, "a removed focused subtree"): keys
from inside a removed subtree reach its former ancestors' handlers. It
passes on a `git archive` export of 71c170f (1.6.4, renderer 1.9.3) and
failed on 1672798.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 7bd7fba)
With the parent link kept (as in 1.6), the layout queue must not treat a
removed node as attached: its `loaded` handler no longer queues its old
parent, a removed container whose layout changed its size no longer
queues its old parent, and its depth in the layout queue counts its own
tree only (it ends at the removed node). Removed-but-alive nodes are
Preserve and KeepAlive roots, and nodes an app removes itself; 1.6 laid
out the old parent synchronously from a removed node's load.

Tests (jsdom, failed with the parent link back and without this):
a removed autosize view's load, and a removed flex container's resize,
leave the old parent's onLayout count alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit b571b99)
A text whose parent lays out (flex or onLayout) is sized by the renderer's
synchronous measure() in Solid's post-mutation pass, before the parent's
flex and before the frame, instead of by the walk and a persistent
`loaded` listener. A text change in a flex container now costs one walk per
drawn frame, no `loaded` event when the app has no listener, and one flex
pass per container whose size changed.

- render() queues a new flex text to be measured (after its onEvent
  listeners are on, so an app's `loaded` hears the layout measure() makes);
  _layoutOnLoad stays for autosize nodes only.
- _textLayoutDirty(), the one helper, is called by the accessors of the
  props the layout reads: text, fontFamily/fontWeight (_writeFontFamily),
  fontSize, lineHeight, letterSpacing, maxWidth/w(width), maxHeight/h
  (height), maxLines, wordBreak, overflowSuffix. It queues the text; the
  layout phase measures the queue and queues the parent only when the
  size flex reads (maxWidth || w, maxHeight || h) changed. A text with
  both max sizes is not measured (flex reads those).
- updateLayout() measures due or never-measured text children before its
  pass (a direct updateLayout(), a container that lays out only now).
- Texts flex sizes (flexGrow, flexShrink, minWidth) are measured again
  after each sweep, so their container runs again; capped at 16 sweeps.
- measure() false (no font description): the text hears `loaded` once
  (a shared listener, run in the frame), and loadFonts() tells when a font
  loaded (internal src/core/fontLoaded.ts), for texts no walk visits
  (5.2: text under a hidden or out-of-bounds ancestor is laid out too).
- Development only: a warning when a walk's layout changes the size of a
  text Solid measures (a layout prop written on el.lng).
- DOM renderer: DOMText.measure() (getBoundingClientRect while
  document.fonts.check says the font is loaded, else false) and
  DOMNode.destroyed; both in domRendererTypes.

Tests: WebGL walks per drawn frame 1 and one pass per container for text
changes, `loaded` heard once by a listener, eager layout under alpha 0 and
out of bounds, culled text whose font loads later, flex-written text
widths settle; jsdom: measured in the post-mutation microtask, direct
updateLayout(), unchanged size lays nothing out, every font prop, the
font-not-loaded wait. layoutQueue's `loaded` cases use an autosize view.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit bcf31d2)
…eview)

DOMText.measure() writes the new size without emitting; the renderer's own
re-measure then found the size unchanged and emitted nothing, so an app's
onEvent.loaded on a flex text heard only the first size (Marquee's text
width went stale). The re-measure now emits when the size differs from
the one `loaded` last told (loadedW/loadedH).

The jsdom fonts mock reports status 'loaded', as a browser does once its
fonts are in: the re-measure runs on a timer then, after Solid's
microtask, which is the order that lost the event. Two contract tests wait
for that timer; the font-not-loaded test sets status 'loading' while it
holds `ready`. New contract test: a flex text's onEvent.loaded hears a
text change (RED before: [{50,20}] only).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit f2c8bf8)
…nts, waiting list)

- measureQueuedTexts skips an entry a run that threw cleared (the count
  was not reset): later runs no longer throw on `undefined._text`.
- At the 16-sweep cap the remaining texts are dropped (measured again at
  their next change): the writes of a layout that never settles had
  scheduled another run, which started over in a microtask loop.
- `contain` writes mark the text due: the DOM renderer sizes a text by it
  (on renderer v2 the measure finds nothing to lay out).
- DOM builds keep a `loaded` listener per measured text that lays the
  container out when the size changed since Solid saw it: a web font that
  loads after the text was measured (document.fonts.check is true for a
  family no face names). isFontLoaded caches the CSS font on the text.
- The font-waiting list is swept of destroyed texts when it doubles; a
  loadFonts() font that fails runs the same pass (fontFailed rethrows).

Tests: the sweep cap (17 passes, one warning, later runs lay out; it hung
the worker before), a throwing measure (2 errors before), contain, a DOM
re-measure at a new size, and a font loaded with renderer.loadFont alone
(the texts' `loaded`, no loadFonts hook).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit f298320)
…s container (T1 review)

T1 measured a text when its fontSize/lineHeight/width/height was written,
but with a `transition` the write starts an animation: the measure saw
the old size and the walk's layouts of the animated values reached
nobody, so the container kept the old size while the text grew (sibling
at 80.44 under a 140.88-wide text; 1.6: 150.88).

While an animation of a text's layout props runs (started by
_sendToLightningAnimatable or animate(), the controller kept on the
text's TextMeasure record), the text hears `loaded` through one shared
listener; the layout phase, in that frame, lays out the parent of each
animating text whose size changed, and drops the texts whose animations
stopped (they stop listening). Two walks per frame only while it
animates, as in 1.6; a later text change walks once again. The list is
swept of stopped or destroyed texts when it doubles.

The development warning skips animating texts and names the cause it
reports (a layout prop written or animated on el.lng).

WebGL test: fontSize 30 -> 60 with a 600 ms transition, the sibling never
overlaps the text in any frame (37 frames, 37 flex passes) and ends at
149.02 (139.02 + 10); a later text change walks once. RED before: the
sibling stayed at 79.51.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 9d8716a)
…ed (T1 review 2)

measureFontWaiting walks the list by index up to its starting length; a
text whose font is still missing is appended again through _waitForFont,
which swept the list once it reached its sweep length. The sweep moved
entries under the loop: texts dropped off the list while still waiting
(nothing measured them again until their next write), others were read
twice, and reading past the compacted end threw (the rest of that
post-mutation run, layout and focus, was skipped).

_waitForFont now sweeps only outside measureFontWaiting (a flag, reset in
a finally); the loop's own tail shift already drops what it measured.

Tests (jsdom, document.fonts.check per family, fontLoaded() as loadFonts
calls it, the DOM renderer's own re-measure held): 120 texts alternating
two families, 100 alternating, 100 then 20; one family loads, then the
other. Each alone was RED: texts still waiting after their font loaded,
and a TypeError reading '_text' for 100 + 20.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit f51c63c)
…T1 review 2)

Round 1 tracked the controllers of a text's layout-prop animations and
stopped listening once they were all 'stopped'. A renderer Animation is
'stopped' until start() and again when it finishes, and el.animate()
hands the controller to the app: one started after the text's next
layout, or started again after it finished, animated with nobody
listening, so the sibling stayed put while the text grew (1.6's
persistent listener handled both).

Once Solid has animated a prop a text's layout reads through the element
(a `transition`, el.animate(), chain()), the text keeps one `loaded`
listener for its lifetime (`_listenTextLoaded`, a closure made once per
text, also used by every measured text in DOM builds): a layout at a size
Solid did not measure lays the container out in that frame; a layout
Solid measured changes nothing and asks for no second walk. The module
list, the controller tracking and their sweeps are gone: nothing but the
renderer node holds the listener, so a destroyed text (mid-animation
too) is not retained (review 2, minor 3).

DOM renderer: `destroyed` is true for the descendants of a destroyed
node too, as renderer v2 destroys the subtree (the font-waiting sweep
reads it).

WebGL tests: el.animate() started again after it finished, and started
after the text laid out again; RED before (sibling at 79.51; 67.42 under
a 124.84-wide text).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 44a15a3)
…review 3)

The three font-waiting regression cases ran in layoutQueue.test.tsx on
the shared module instance (vitest isolate: false). The 16-sweep test
before them left its never-settling onLayout running; its text writes
scheduled the DOM renderer's re-measure timer, which flushed the new
cases' texts and woke the waiting list during render, growing its sweep
length past what the mixed pass reached: with the guard removed the
cases still passed in a file or suite run.

- tests/fontWaiting.test.ts: each case imports a fresh @solidtv/solid
  (vi.resetModules) with its own DOM renderer, builds its tree with that
  instance's ElementNode (no JSX: the JSX runtime is the shared one), and
  asserts the precondition that no waiting text heard `loaded` before
  fontLoaded(). With the _waitForFont guard removed, all three fail in
  the file run and in the full suite (the 100 + 20 case with a
  TypeError); with it, they pass.
- The 16-sweep test stops its loop and lets the DOM re-measure timer run
  before and after disposing its container.
- Two test type fixes (tests/tsconfig.json) in contract-text and
  flex-text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 5a47510)
chiefcll and others added 4 commits November 19, 2026 14:59
From 46ba87e on the 1.8 branch (the layout.md part only), with the
version and the migration pointer adjusted for main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main's child-list test pinned the 1.6 result (appended). Stream N's B19
fix keeps the node where it is, as DOM insertBefore does, so Solid's
adjacent-item swap no longer sends the item to the end.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Lost while merging stream T's version of the test with main's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… first press

The "animations on" tests of VirtualRow and VirtualGrid stub
requestAnimationFrame and then give each press four setTimeout(0) turns.
Animations are on by default, so an earlier test's scroll transitions can
leave the DOM renderer's loop with animationFrameRequested set and a
jsdom frame up to ~16 ms away. Until that frame runs the loop requests no
other, the stub is never called, and the press's transition does not
move: CI saw y stay at 40 on the first ArrowDown. With isolate: false it
depends on the file order (reproduced with
`--maxWorkers=1 --sequence.shuffle.files --sequence.seed=3`, and seed 4
for the VirtualRow test).

Both tests now wait one jsdom frame after stubbing. A leftover frame runs
first and its next request goes to the stub. The race was already on
main; this branch's test set changed the order that exposed it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chiefcll
chiefcll merged commit 180d90f into main Nov 20, 2026
1 check passed
chiefcll added a commit that referenced this pull request Nov 20, 2026
…rness from the 1.8 branch (#93)

* docs: renderer 2.0 setup, Building for TVs, text measured before the frame

From the 1.8 branch (46ba87e, 1ff8d59, a0808a0, 1e344f0, 7d2d71c and the
stream T layout.md entries):
- render.md and basics.md: no render or font engine to set; load an SDF
  font per family and register shader types; renderEngine, fontEngines and
  stage.shManager listed as removed in renderer 2.0.
- deploy/build.md (new, in the sidebar): terser `reduce_funcs: false`.
- layout.md: flex text is measured with `measure()` before the frame;
  points at MIGRATION-1.8.md.
- virtual.md: factorScale has no effect since 1.7.
- useHold.md: the release handler is `onEnterRelease`.
- effects.md: a `shader` tuple's type must be registered. 1.8 said Solid
  registers `rounded`, which it does not: it names registerShaderType and
  registerDefaultShaders instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs: MIGRATION-1.8.md, from 1.7.x to 1.8

What #89-#92 changed for apps, adapted from the 1.8 branch's
MIGRATION-1.7.md: one flex engine and the flex fixes B5-B12, text sized
before the frame and laid out eagerly, one reactive flush per focus change,
States changes and B2, diffed state application and per-object style
caching, the Row/Column transition cache, B19 draw order, B20, and the
terser build setting.

Left out, as 1.7.x already shipped them: the renderer 2.0 breaks, the
renderEngine/fontEngines/shManager absorption, B1, B3, B4, B13-B17, B21
and the Virtual/VirtualGrid layout changes. Each entry keeps what changes
and the upgrade step; the measurements stay in docs/perf/log.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(perf), bench: the 1.8 rewrite's design, measurements and harness

From the 1.8 branch:
- docs/perf: the methodology (README), the log, the Phase 0 profiles and
  summaries, the Checkpoint 2 series summary, the route timings, the survey
  verification and the text-flex alternatives study. The raw per-run JSON
  records are left out, as .gitignore already says; their summaries are
  committed.
- docs/superpowers: the design, the Phase 2 plan, the Checkpoint 2 report
  and the renderer proposals (the rewrite brief is already on main).
- bench: the demo-app route timing and bundle scripts (bench/demo), the
  renderer v2 arm, and the harness fixes.
- .gitignore: bench/.results-tmp and .superpowers.

The log notes that this work was named 1.7 on the branch and shipped as 1.8.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant