Repository navigation
feat(sandbox): Animated Layout Perf, measuring useAnimatedLayout for an item in a long list - #8629
Conversation
…t around a size change When something inside a registered area changes size, the content after it glides from its old place to its new one with a compositor-only translate instead of jumping (architecture:react-component-runtime INV12, proposed in #8463). - motion/animatedLayout.ts: one batched measurement before and after the change; a bounded parentElement/nextElementSibling walk up to the area (no TreeWalker), descending only through display: contents; absolute and fixed elements skipped; only elements whose rectangle changed and that are visible move; scale-corrected; Web Animations translate with composite: 'add', feature-tested per call with fallbacks; offscreen elements land silently; Reduce Motion cross-fades with no travel; every pointer. - useAnimatedLayout(ref) (public) registers an area; reportLayoutChange stays internal. ScrollableArea registers its viewport itself. - Collapsible and TreeList adopt it: the shown content plays its own entrance, and the chevron turns, on the same placeholder layout-change role as the glide. - Storybook: Core/Animated layout, with a nested tree, a Collapsible, a field error, load more, wrapping tags, plain divs, a display: contents wrapper, a sticky header and an absolute badge. Draft for trying it out; tests, docs and a changeset follow.
…ollapsible and TreeList take as animatedLayout
The API shape the owner set: the hook takes {containerRef} and returns an
opaque handle; Collapsible and TreeList accept an animatedLayout prop and
report their size changes through it, with no context registration.
Without the prop, a component keeps today's behavior, its chevron
included. ScrollableArea no longer registers itself: an app passes the
ScrollableArea's ref as containerRef. The story uses exactly this shape.
Adds the changeset.
…subpixel rounding A real-Chromium check showed unscaled followers moving by 79.92 px for an 80 px shift: subpixel rounding made rect.width / offsetWidth read a hair off 1. A scale within 1% of 1 is now treated as none.
…+ Add tag wraps and its followers move
…tion by pointer, visible-part rule for the changed element, top-layer and hidden skipped, chevron on the spring)
- One shared motion role: the glide, the changed element's entrance and the disclosure chevron all play springs.settle, resolved through the internal motion-role registry (a theme's --motion-springs-settle reaches all three); the glide's keyframes are sampled from the spring and played linearly. - Reduce Motion by pointer (design:reduced-motion DR1-DR3): a cross-fade under a coarse primary pointer, an immediate change otherwise. - The changed element outside the area's visible part lands without animation; hidden and top-layer elements are skipped. - Collapsible and TreeList take the chevron from their Icon's icon target and set its transition before the change commits; no handle leaves every inline value untouched. - Tests: the walk, motion and handle in jsdom; Collapsible and TreeList with and without a handle; one real-browser case per AST-105 Coverage row, plus FR2-FR5. - Docs: the useAnimatedLayout hook doc (FR7 text), the animatedLayout prop in the Collapsible and TreeList docs and records, and a Before and after story.
… registry only Motion roles are internal (spec:AST-094 DEC-11): the glide, the changed element and the chevron share the registry's one value, and a scope's --motion-springs-settle changes nothing. The tests assert that instead of an override.
… and compare scrolling with and without a handle Run in real Chromium (all 20 cases, three repeats): the page helper's microtask wait is plain JavaScript; the out-of-view and nested-area cases wait for the first change's glide to finish before the second; and the FR3 scroll case compares the area's scroll frame by frame with and without a handle, since the browser's own scroll anchoring moves it either way.
…ed ones and retargets on the compositor - A single-mode CollapsibleGroup measures every item a toggle changes (the one that closes as well as the one that opens), so the items between glide with the content after the group. Items holding a handle register their measurement with the group. - A measurement no commit claims by the next frame (a controlled owner refused the toggle) is dropped, so it never moves unchanged rows later. A change nothing measured (an owner set isOpen directly) lands at once, entrance included. - The follower glide is one replace-composited translate, which the compositor runs (architecture:react-component-runtime INV12). An element already gliding is retargeted: its glide stops and the new one starts from where it is on screen, so it keeps moving without a jump. - INV12's source boundary check (no layout property animated, the walk only through parentElement / nextElementSibling, nothing public, only the hook and the adopters use it) and a real-browser case on a throttled phone over a 10-level by 50-sibling tree with two changes in one frame.
spec:AST-105's Coverage row: an element already moving keeps its running motion and adds the new move. The new glide now samples the sum of the running glide's remaining curve and the new move into one replace-composited translate, so the element keeps its speed through the change instead of restarting from rest. Every animation of a change starts on the document timeline's current time, so a replaced glide moves in the very frame it is replaced and the changed element and its followers share one start. Tests: the carried speed (jsdom) and, in a real browser, no jump and no lost speed across the change.
…e morph once Core has it, its own compositor translate until then
…st adopt it in their own pull request The module, the hook, their tests and docs, and the INV12 record line stay here. Collapsible's and TreeList's adoption (their animatedLayout prop, docs and records), the CollapsibleGroup measurement, the adopter tests and the Storybook story move to a stacked pull request, so each lands and reverts on its own. The changeset now describes the hook alone.
Restores the adoption from the module pull request onto it: the animatedLayout prop on Collapsible and TreeList (docs and records), the CollapsibleGroup measuring every item a toggle changes, the adopter tests, and the Storybook story. The story keeps only adopting components and plain following content; its demos that drove the internal reporting functions directly are gone.
…motion spec:AST-105 FR4: the changed element plays its own animation when it exits too. holdLayoutExit keeps a closing element on screen but out of flow (absolutely positioned where it is), so the content after it glides up at once, and conceals it upward from its bottom edge on springs.settle (a fade under Reduce Motion with a coarse pointer, nothing with a fine one); the component hides it when the exit finishes, and releaseLayoutExit puts it back, including when it opens again mid-exit. The throttled-tree browser case now reads its animations in the same task, so a slow round trip can't outlast the glide.
…'s exit spec:AST-105 FR4: the changed element animates when it exits too. A measured close keeps the Collapsible's content (or the TreeList row's child group) rendered, inert and hidden from assistive technology, while holdLayoutExit holds it out of flow and conceals it on springs.settle; the rows after it glide up at once, and the content hides (or the group unmounts) when the exit ends. Opening again mid-exit ends it. Rows of an exiting group leave the tree's keyboard order at once. An unmeasured close, no handle, or an exit that lands at once hides it in the same commit.
…es with its row; the exit stays in flow - This pull request is now the internal module only: the public hook, its docs and the chevron's transition move to the adoption pull request, so nothing public appears before a component can take the handle. - A changed element that an earlier change in the same frame displaced moves with its row, by its total change (AST-105 FR3), while it plays its own entrance or exit; an element not rendered before the change has no old place and does not move. - The exit keeps the element in flow where it is and gives up its space with a negative end margin as large as its box, so it scrolls and clips with its container and keeps its width (no offset-parent positioning). - Browser proofs: the sticky row uses a stuck header after the change, the flex row a wrapped item and a row-direction neighbor whose rectangle does not change; new cases for the displaced changed element and the exit in a scrolled area.
… chevron move here The module pull request is now internal only, so this one carries the public face with the components that take it: useAnimatedLayout, its doc page and export (and its docsite route), applyLayoutChangeTransition and its tests, and the boundary test's list of users (the hook, Collapsible and TreeList). The adopters follow the module's in-flow exit: their tests check the exit's end margin instead of absolute positioning. The changeset describes the hook and the two adopters together.
…e app moves are left alone - holdLayoutExit measures the layout after the element with it hidden and sets the end margin that puts that layout there, so a gap or collapsing margins come out exact and nothing jumps when the element hides; where no margin can free the space (a grid track and its gap) the exit lands at once instead. - The held element is inert while it conceals (no focus, no pointer, nothing read); the module sets and releases it. - A follower with its own transform, translate, rotate or scale, or with a running transform animation the module did not start, takes its final place at once, as AST-105's Coverage lists for elements the app moves. - Tests: the exact space with a gap (jsdom), the grid fallback, app-moved followers; real-browser cases for a flex gap and collapsing margins, and for app-moved followers.
… left alone) into the adoption The module now makes a held element inert, so Collapsible's content and TreeList's child group drop their own inert and aria-hidden while exiting (TreeList keeps the marker that takes the group's rows out of the keyboard order).
…red close, and restores what it replaced - giveUpSpace measures the first element after the closing one in the area (its next sibling, or an ancestor's below the area), not the parent's edge, which a collapsed negative margin never moves: a Collapsible-shaped close (the last child of a plain wrapper) now plays its exit. - holdLayoutExit holds only a close a change in the area measured, and its documentation asks for the call after animate() reports it measured. - releaseLayoutExit puts back the element's own inert and inline values. - AST-105's out-of-coverage list names a closing grid item whose track or gap changes when it hides (owner-approved): it hides at once, without its exit. - Tests: an unmeasured close holds nothing; prior values restored; a real- browser case for the plain-wrapper shape.
…d holds only a measured close) into the adoption
…al next box and checks what follows its container - The flush stops every running glide and reads every new place before starting any glide, and an element inside another moving element moves only by its own change: nested changes compose whichever is reported first (AST-105 FR3). - The exit's search for the next box enters a display: contents wrapper, as the follower walk does. - The exit checks the content after its container on both axes, so a flex-row item that sets its row's height is refused instead of leaving the content below to jump. - A refused exit puts back the element's own end margin and drops its change, so the content after it takes its final place at once. - AST-105's out-of-coverage line names both layouts no margin frees (owner- approved). - Tests: a refused hold keeps its own margin and glides nothing; real- browser cases for nested changes reported inner-first, a display: contents next box, and a tall flex-row item.
…ext box and container checks) into the adoption
…, the browser's own layout cost A Glide control (With handle / No handle) runs the same list without useAnimatedLayout, so the walk's share of a toggle is the difference.
There was a problem hiding this comment.
Changes requested: the page runs as described in Chromium, and its numbers show the walk growing with the rows after the change, but its comparison flow can mislead whoever reads the numbers. Please fix these before it lands with its base:
- Saved baselines live only in component state, so the reload a build change needs clears them, although the help text and description promise cross-build comparisons (
page.tsx:190,:475-477). - Stop publishes a partial run under the fixed "6 toggles" badge and lets it be saved as the baseline (
page.tsx:429,:444). - With six toggles,
median()returns the upper middle value of three opens and three closes, so it reports only one kind of toggle (page.tsx:120-125). - The middle item's copy says every row after it glides and that the walk visits the rows around it; only the rows in view move, and the walk reads the elements after the item (
page.tsx:168-172).
[Automated review]
…ports nothing for a stopped run, and takes a true median - Saved baselines go to localStorage per rows, rendering and glide, so the reload a build change needs keeps them (read after hydration). - A stopped run publishes no metrics, so a partial run can neither read as a full one nor be saved as a baseline. - The median of an even count is the mean of its two middle values: a run's three opens and three closes both count. - The middle item's copy says what moves (the rows after it that are in view) and what the page measures.
There was a problem hiding this comment.
Changes requested: the page builds, its route exports, and the earlier findings are fixed, but two states still mislead whoever reads its numbers. Please fix these before it lands with its base:
- No handle runs stop the clock before the browser's style and layout, so the help text's "with handle minus no handle" charges the walk about 5 ms at 5,000 rows and 9 ms at 10,000 that the browser spends anyway; add a layout read such as
void viewport.offsetHeight;beforewalks.push(page.tsx:327), or say that No handle times React's commit only. - After a reload every metric reads "no baseline" although the baseline is saved; show "no baseline" only when none is saved for the configuration (
page.tsx:109-112).
[Automated review]
…th modes, and a saved baseline reads as saved after a reload - An uncounted layout read closes each toggle's clock, so No handle times the browser's own style and layout for the change too, and with the handle minus without is the walk alone. - A metric reads no baseline only when none is saved for the configuration; before a run it reads baseline saved.
There was a problem hiding this comment.
Approval recommended: the page builds, its route exports, and the two issues from the last review are fixed, so No handle now includes the browser's layout and a saved baseline reads as saved after a reload. Before #8634 compares against it, consider refreshing the description's table, which predates the last two commits (it shows 5,007 and 10,007 rectangles, and No handle times taken without the browser's layout). The page can land with or after its base, since useAnimatedLayout and Collapsible's animatedLayout prop are not on main yet.
[Automated review]
There was a problem hiding this comment.
Changes requested: the page builds, its route exports, and Stop and saved baselines behave as its help text says, but the description no longer matches what the page measures.
- Regression: since #8634 merged into this branch the page reads 118 rectangles at 1,000, 5,000 and 10,000 rows, so the description's "The walk is linear in the rows after the change, and the page now shows that", its "before the module's walk changes" and its table (1,004, 5,004 and 10,004 rectangles, 9 elements animated, 82.7 ms at 5,000 rows) need a refresh from a run at this head, or a label as the pre-#8634 baseline.
No code change is needed. The opening paragraph about waiting for #8568 and #8482 and retargeting can go too, since both have merged.
[Automated review]
There was a problem hiding this comment.
Approved pending CI: the heavy suites (build, test and docsite-test) are deferred on this head and run before merge.
The description now labels its table as the baseline from before #8634, and its head numbers match the page: 118 rectangles read at 1,000, 5,000 and 10,000 rows, with 10 rows animated. No code change is needed.
Optional:
- Miss: the three embedded screenshots come from an older build of the page (5,007 rectangles read, the earlier middle-item copy and help text); re-take them at this head or caption them as the pre-#8634 build.
- The comment at
page.tsx:236-237says the middle item always renders, but in Virtualized mode it renders only inside the window.
[Automated review]
There was a problem hiding this comment.
Changes requested: the page builds, its route exports, and its numbers match the description at this head (118 rectangles read at 1,000, 5,000 and 10,000 rows), but it carries its own copies of helpers the other perf pages already have.
- Miss:
formatMs,formatCount,formatChangeand the long-task observer inpage.tsx(lines 100-121 and 291-303) copyformatDurationandformatCountfromdiffviewer-perf/benchmark.ts,formatBenchmarkChangefrommarkdown-perf/benchmark.tsandwatchLongTasksfromdiffviewer-perf/page.tsx, and the long-task copy has already drifted, so in Firefox, which has no Long Tasks API, a run reports "Long tasks 0" where DiffViewer Perf shows no reading; please call or extend those helpers from one shared Sandbox module and delete the page's copies.
Optional: the description's screenshots come from an older build (they show 5,007 rectangles read), and the comment at page.tsx:236-237 says the middle item always renders, which does not hold in Virtualized mode.
[Automated review]
…Long Tasks API Firefox has no Long Tasks API, so the page reported 'Long tasks 0'. It now shows no reading, as DiffViewer Perf does.
There was a problem hiding this comment.
Changes requested: the page builds, its route exports, and the long-task fields now show no reading in Firefox instead of a zero, but the page still carries its own copies of helpers the other perf pages already have.
- Miss:
formatMs,formatCount,formatChangeand the long-task observer inpage.tsx(lines 100-121 and 291-303, plus the new null rule at 366-367) copyformatDurationandformatCountfromdiffviewer-perf/benchmark.ts,formatBenchmarkChangefrommarkdown-perf/benchmark.tsandwatchLongTasksfromdiffviewer-perf/page.tsx, so a later fix to either copy misses the other page; please call or extend those helpers from one shared Sandbox perf module in this pull request and delete the page's copies.
A follow-up pull request does not clear this, because the existing helpers can already serve this page. Optional: the description's screenshots still come from an older build (they show 5,007 rectangles read), and the comment at page.tsx:236-237 says the middle item always renders, which does not hold in Virtualized mode.
[Automated review]
…d long-task helpers The page imports formatDuration and formatCount from DiffViewer Perf, formatBenchmarkChange from Markdown Perf, and watchLongTasks, which moves from DiffViewer Perf's page into its benchmark module because a Next.js page exports only page members. formatBenchmarkChange gains optional empty-state labels (default '—', so Markdown Perf is unchanged), which keep this page's 'no baseline' and 'baseline saved'. The Virtualized comment now says the middle item renders only inside the window.
There was a problem hiding this comment.
Approval recommended: the Animated Layout Perf page now calls the shared formatDuration, formatCount, formatBenchmarkChange and watchLongTasks helpers, which clears the last review's request, and at this head the page builds, its route exports, and a run reads 118 rectangles at 1,000, 5,000 and 10,000 rows.
Optional cleanups:
- In
markdown-perf/benchmark.test.ts, the new empty-label test starts inside the existing one, so "formats missing, zero, positive, and negative baseline changes" now checks only the missing cases; moving the new test below line 34 makes both names match their checks. type Renderinginpage.tsx(line 46) sits between the imports; moving it below them keeps the import block together.- The description's screenshots still come from an older build (they show 5,007 rectangles read).
[Automated review]
| expect(formatBenchmarkChange(10, null)).toBe('—'); | ||
| }); | ||
|
|
||
| it('shows a caller-supplied empty label when there is no baseline or no value', () => { |
There was a problem hiding this comment.
Optional: this test starts inside the existing one, so "formats missing, zero, positive, and negative baseline changes" now checks only the two missing cases (lines 21-22), and the zero, positive and negative checks (lines 31-34) run under this test's name. Move the }); at line 23 and this test below line 34 so each name matches its checks.
| import {Heading, Text} from '@astryxdesign/core/Text'; | ||
| import type {AnimatedLayout} from '@astryxdesign/core/hooks'; | ||
|
|
||
| type Rendering = 'full' | 'virtualized'; |
There was a problem hiding this comment.
Optional: the new imports below land after this alias. Move type Rendering below the import block.
Primary intent
A fullscreen sandbox page that measures
useAnimatedLayoutfor an item in the middle of a long list. It sits beside Markdown Perf and DiffViewer Perf and follows their layout. Sandbox only: no package change and no Changeset. It's "other" because it's a measurement tool, not a product change.User or maintainer impact
Maintainers can see what a glide costs at scale, and compare builds as the module's walk changes:
Problem and solution fit
The module walks the content after a change and reads its rectangles. Nothing so far showed what that costs in a long list, or under a slower CPU. This page does, with the controls the question needs (row count, rendering), and baselines for before/after comparisons across builds.
Authority
The request for a
useAnimatedLayoutperf test for items in the middle of a long list.spec:AST-105andarchitecture:react-component-runtimeINV12 define what the module does; this page only measures it.Change and evidence
Baseline from before #8634 (real Chromium, the built sandbox page, median over 6 toggles of the middle item), kept to show what #8634 changed. "No handle" is the same list without
useAnimatedLayout, so it shows the browser's own cost (each toggle's clock closes with a layout read in both modes, so the difference is the walk):Before #8634 the walk was linear in the rows after the change, as the table shows. #8634 bounds it and is merged into this branch, so at this head the page reads 118 rectangles at 1k, 5k and 10k rows (from a review run at this head); #8634 reports its after numbers from this page.
Desktop, after a run (5k rows, every row), with the middle item open:
390 px. The list sits below the metrics; nothing in view moves, so 0 elements animate:
Reduce Motion, desktop. With a fine pointer the change lands at once, so 0 elements animate:
Scope
Testing
pnpm -F @astryxdesign/sandbox build: prerender, plus export verification against the route list, which gains/pages/animated-layout-perf/.Maintainer update
Merged
mainafter #8482 and #8568 landed, and retargeted tomain. This page's own files are unchanged. The table above is labelled as the pre-#8634 baseline, since #8634 bounds the walk and is part of this head.This round the page uses the other perf pages' helpers instead of its own copies:
formatDurationandformatCountfrom DiffViewer Perf,formatBenchmarkChangefrom Markdown Perf, andwatchLongTasks, which moves from DiffViewer Perf's page into itsbenchmark.ts(a Next.js page exports only page members). So without the Long Tasks API (Firefox) this page shows no reading, as DiffViewer Perf does.formatBenchmarkChangegains optional empty-state labels that default to '—', so Markdown Perf is unchanged; this page keeps its 'no baseline' and 'baseline saved'. Changes now show one decimal place, as on the other pages. Both helper modules have new tests. The Virtualized comment now says the middle item renders only inside the window. Moving every perf page's helpers into one shared Sandbox module is a separate follow-up.(Posted by Cindy's agent on her behalf.)