Repository navigation
chore(core): the internal module for size-change glides (spec:AST-105, INV12) - #8482
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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
…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
PR Analysis Report
|
…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.
…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.
|
/approve-spec 2f7cedb |
There was a problem hiding this comment.
Thanks for the fixes: the exit now frees exactly its space with gaps and collapsing margins, followers the app moves are left alone, and the INV12 interim has an engineering owner's approval on this head. One change is still needed before approval: when the closing element is the last child of a plain block wrapper, as Collapsible's content is, holdLayoutExit measures the wrapper's edge, which the collapsed negative margin never moves, so the exit lands at once and the content vanishes while the rows glide (animatedLayout.ts:659-663, AST-105 FR4).
- Measure where the content after the element actually sits instead of the parent's edge, and add that layout to the exit browser cases.
- The grid-gap fallback also skips FR4's exit: hold the element another way there, or have an engineering owner name it in AST-105's out-of-coverage list.
holdLayoutExit's comment asks for the call beforeanimate(), which holds a close nothing measured, andreleaseLayoutExitstripsinertand inline values the exit did not set.
[Automated review]
| const parent = element.parentElement?.getBoundingClientRect(); | ||
| if (parent == null) { | ||
| return 0; | ||
| } | ||
| return isRow ? (rtl ? -parent.left : parent.right) : parent.bottom; |
There was a problem hiding this comment.
For a last child this reads the parent's end edge. In block flow, when the parent has no bottom border, padding or formatting context of its own (Collapsible's root), the negative end margin collapses through it: in a Chromium probe the wrapper's bottom stayed at 124 px while the paragraph after it moved from 124 px to 40 px, exactly where it sits once the content is hidden. The check at line 698 then refuses the hold, so the exit lands at once, against AST-105 FR4. Measuring the first element the walk reaches after it would see the real target.
| * fades instead. Call it in the layout effect of the commit that closes the | ||
| * element, before the change's `animate()`. |
There was a problem hiding this comment.
Only animate() knows whether the change was measured, so holding first can hold a close nothing measured: in a probe the row after it moved up at once into the held element's place and overlapped it by 81 px for the whole exit. #8568 calls animate() first and holds only a measured close, which works because the flush is a microtask; documenting that order would keep the next adopter from tripping on it.
| } | ||
| exits.get(element)?.cancel(); | ||
| exits.delete(element); | ||
| element.removeAttribute('inert'); |
There was a problem hiding this comment.
This removes inert (and the loop below removes pointer-events and both end margins) even when the element had them before the exit, so content an app or component made inert is reachable again after a release. Recording the prior values in holdLayoutExit and restoring them here would keep the promise in the comment above: remove only what the exit set.
…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.
|
/approve-spec 52841d7 |
There was a problem hiding this comment.
Thanks for the fixes: the exit now measures the content after it, holds only a measured close and puts back what it replaced, and the INV12 interim and the new AST-105 line carry an engineering owner's approval on this head. A few changes are still needed before approval, and because this pull request edits both records, the fix commit will need a fresh /approve-spec from an engineering owner:
- Nested changes in one frame compose only when the outer one is measured first; measured inner first, rows inside the outer change's follower start 80 px too high (
animatedLayout.ts:451-512, AST-105 FR3). - The exit is held where its margin can't free the space, a
display: contentsnext element (as Tooltip and Theme render) or a flex-row item that sets its row's height, so the content after it jumps 8 px or 80 px when the element hides. - The grid fallback still glides the content after the item, which the new AST-105 line says takes its final place at once, and a refused hold removes the element's own inline end margin.
- Please add a nested inner-first case and a Core
display: contentsfollower to the browser spec.
[Automated review]
| running.animation.cancel(); | ||
| glides.delete(element); | ||
| } | ||
| const after = element.getBoundingClientRect(); |
There was a problem hiding this comment.
This reads the follower's new place after the glides of followers processed before it have started, so a follower inside another follower gets the right move only when its moving ancestor came first. With folder A (80 px) and folder B1 inside the following folder B (40 px) opening in one frame, measuring B1 first gave row B2 a 120 px glide inside B's 80 px glide: it started 80 px above where it was and travelled 200 px (Chromium). AST-105 FR3 says nested changes compose. Reading every follower's rectangle before starting any glide, then subtracting its nearest moving ancestor's move, would make this independent of the order.
| let sibling = node.nextElementSibling; | ||
| while (sibling != null) { | ||
| const style = view?.getComputedStyle(sibling); | ||
| if (style == null || takesPart(sibling, style)) { |
There was a problem hiding this comment.
A display: contents sibling passes takesPart and is returned here, but it has no box, so every startEdge reading is 0 and the margin falls back to the border box. In a flex column with gap: 8px before a display: contents wrapper (Tooltip and Theme render one), the row after it ended 8 px short and jumped when the element hid. Descending into it, as collectFollowers does, would measure the real next box.
| } | ||
|
|
||
| /** An element's start edge along the main axis (RTL rows read right to left). */ | ||
| function startEdge(element: Element, isRow: boolean, rtl: boolean): number { |
There was a problem hiding this comment.
For a closing flex-row item this reads only the inline axis, even when next is the element after the row. With the closing item 120 px tall beside a 40 px item, the hold was accepted, nothing below glided, and the row below jumped 80 px when the item hid. Measuring the block axis when next sits outside the row, and refusing the hold when either axis misses, would let the follower glide instead.
| const guess = startEdge(next, isRow, rtl); | ||
| element.style.setProperty(property, `${-size + (target - guess)}px`); | ||
| if (Math.abs(startEdge(next, isRow, rtl) - target) > 1 && before !== target) { | ||
| element.style.removeProperty(property); |
There was a problem hiding this comment.
This removes the end margin outright, so an element that had its own inline margin-block-end: 12px comes back with none after a refused exit, against “Returns false, setting nothing” above. Putting back the prior value, which holdLayoutExit already records, would keep that promise.
| ] as const, | ||
| ), | ||
| }; | ||
| if (!giveUpSpace(element, area)) { |
There was a problem hiding this comment.
When the hold is refused here, the change stays measured in the batch, so once the adopter hides the item the flush glides the content after it (88 px in a grid with row-gap: 8px). The new AST-105 out-of-coverage line says that content takes its final place at once. Either drop this change's followers when the exit is refused, or have the line say the content glides.
…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.
|
/approve-spec bc32d66 |
There was a problem hiding this comment.
Thanks for the fixes: nested changes now compose in any order, the exit finds the real next box and checks what follows its container, a refused hold keeps the element's own margin, and the INV12 interim and the new AST-105 line carry an engineering owner's approval on this head. Two changes are still needed before approval, and because this pull request edits both records, the fix commit will need a fresh /approve-spec <full head SHA> from an engineering owner (the author may do so as one):
- Under a scaled ancestor the exit adds a screen-pixel correction to a layout-pixel margin (
animatedLayout.ts:784-786), so in a gap stack or with collapsing margins the hold is refused and the content after it jumps; dividing the correction by the element's scale and adding a scaled exit case to the browser spec would fix it. - The
display: nonemeasurement (animatedLayout.ts:776-781) restarts CSS animations inside the closing section and firesanimationstartagain; measuring with the element taken out of flow another way, such as a temporaryposition: absolute, would keep them running.
[Automated review]
| element.style.setProperty(property, `${-size}px`); | ||
| const guess = placeOf(next, rtl)[axis]; | ||
| element.style.setProperty(property, `${-size + (target[axis] - guess)}px`); |
There was a problem hiding this comment.
size is layout pixels (offsetHeight), but target[axis] - guess comes from getBoundingClientRect(), which is screen pixels. Under a scale(0.5) ancestor an 8 px gap reads as 4 px, the margin lands 4 px of layout short, the check below refuses the hold and the content after the element jumps (Chromium probe: 44 px on screen; the same layout unscaled glides 88 px). AST-105 Coverage says elements under a scaled ancestor move corrected for the scale. Dividing the correction by the element's scale on this axis (scaleOf, as the glide does) would fix it.
| const display = element.style.getPropertyValue('display'); | ||
| const priority = element.style.getPropertyPriority('display'); | ||
| element.style.setProperty('display', 'none', 'important'); | ||
| const targets = checked.map(box => placeOf(box, rtl)); | ||
| const target = targets[0]; | ||
| element.style.setProperty('display', display, priority); |
There was a problem hiding this comment.
Toggling display: none here, even for one forced layout, cancels the CSS animations inside the element and restarts them when the display comes back: a spinner moved 1 s in came back at 0 ms with animationcancel and animationstart fired (Chromium probe). Taking the element out of flow for the measurement without changing its display, such as a temporary position: absolute, would keep them running.
…easurement keeps CSS animations running - The space correction is read in screen px and the margin is in the element's own: it is now divided by the element's scale on that axis, so an exit under a scaled ancestor frees exactly its space (AST-105 Coverage). - The layout without the element is read with it taken out of flow by a temporary position: absolute, not display: none, which restarted the CSS animations inside it. - Real-browser cases: a gap stack under a scaled ancestor, and a spinner inside the closing element that keeps its time with no animationstart.
|
/approve-spec e4b19b0 |
There was a problem hiding this comment.
Thanks for the fixes: the exit now lands exactly under a scaled ancestor and keeps CSS animations inside a closing section running, and the new browser cases for both pass here and fail against the previous revision. Every change matches spec:AST-105 and INV12, the INV12 interim and the new AST-105 out-of-coverage line carry an engineering owner's approval on this head, and the module stays internal until #8568 adopts it, so nothing further is needed from this review. Optionally, asserting the exit's start time and duration against its follower in the closing browser case would guard AST-105 FR4's same-motion exit.
[Automated review]
| exitDuration: Number(timing?.duration), | ||
| followerDuration: window.motionOf('#a')[0]?.duration ?? null, |
There was a problem hiding this comment.
Optional: exitDuration and followerDuration are read here but never asserted. Adding expect(result.exitDuration).toBeCloseTo(result.followerDuration, 3) (and comparing the exit's start time with the follower's) would guard AST-105 FR4's same-motion exit; a probe shows both start together over 734.8 ms today.
|
Posted by Cindy's agent on her behalf. Cindy's decision on content before a changed element: the animated layout also moves earlier siblings. At each level, the bounded walk collects earlier siblings as candidates too, and the same rule applies: only an element whose rect changed and that is visible moves. This covers centered rows, |
# Conflicts: # packages/core/src/motion/animatedLayout.boundary.test.ts # packages/core/src/motion/animatedLayout.test.ts # packages/core/src/motion/animatedLayout.ts
…an item in a long list (#8629) * feat(core): useAnimatedLayout, one module that glides the layout shift 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. * feat(core): useAnimatedLayout({containerRef}) returns a handle that Collapsible 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. * fix(core): the layout glide corrects only a real ancestor scale, not 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. * chore(storybook): the Animated layout story's tags row is narrow, so + Add tag wraps and its followers move * Merge 8ba53b4 (main, AST-105 current) into the animated layout draft * wip(core): animated layout follows AST-105 (springs.settle, Reduce Motion by pointer, visible-part rule for the changed element, top-layer and hidden skipped, chevron on the spring) * feat(core): useAnimatedLayout follows AST-105 - 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. * chore(storybook): the story's internal-reporting demos say they are story-only * chore(docsite): the ShadCN route lock lists the useAnimatedLayout hook page * fix(core): the animated layout reads springs.settle from the internal 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. * test(core): the animated-layout browser proofs settle between changes 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. * fix(core): animated layout measures every grouped change, drops refused 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. * fix(core): a retargeted glide keeps its motion and adds the new move 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. * docs(architecture): INV12 plays the glide through the shared rectangle morph once Core has it, its own compositor translate until then * docs(architecture): rewrap INV12 * refactor(core): useAnimatedLayout lands alone; Collapsible and TreeList 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. * feat(core): Collapsible and TreeList adopt useAnimatedLayout 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. * feat(core): the changed element's exit, held out of flow on the same 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. * Merge the module's exit (feat/animated-layout) into the adoption * feat(core): a Collapsible's or TreeList row's close plays the content'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. * test(core): the exiting group's rows leave the tree's keyboard order * chore(changeset): Collapsible and TreeList adopt animatedLayout * fix(core): the internal module alone; a displaced changed element moves 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. * Merge feat/animated-layout into the adoption; the public hook and the 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. * fix(core): the exit frees exactly its space and is inert; elements the 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. * Merge feat/animated-layout (an exact, inert exit; 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). * fix(core): the exit measures the content after it, holds only a measured 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. * Merge feat/animated-layout (the exit measures the content after it and holds only a measured close) into the adoption * fix(core): nested changes compose in any order; the exit finds the real 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. * Merge feat/animated-layout (nested changes in any order; the exit's next box and container checks) into the adoption * fix(core): the exit's correction follows a scaled ancestor, and its measurement keeps CSS animations running - The space correction is read in screen px and the margin is in the element's own: it is now divided by the element's scale on that axis, so an exit under a scaled ancestor frees exactly its space (AST-105 Coverage). - The layout without the element is read with it taken out of flow by a temporary position: absolute, not display: none, which restarted the CSS animations inside it. - Real-browser cases: a gap stack under a scaled ancestor, and a spinner inside the closing element that keeps its time with no animationstart. * Merge feat/animated-layout (scale-corrected exit; measured out of flow) into the adoption * fix(core): Collapsible and TreeList report every change, whatever caused it spec:AST-105 FR1: the component reports each change. A click was the only path measured; an owner-set isOpen, a group's controlled value or isExpanded changed in items landed at once. Both components now measure in the commit itself, before React changes the DOM, through a small internal LayoutChangeSnapshot (getSnapshotBeforeUpdate): it runs only for a render that commits, once under StrictMode, and keeps render pure. The exit state is derived from the open state as it changes, during render, so any close keeps the content for its exit; the chevron takes the spring on every change. CollapsibleGroup no longer needs its measurement registry: each item measures its own change. Also: the set-state-in-effect reasons name the layout reads holdLayoutExit decides from, the Verification rows fill every column, and a browser spec renders the Core/Animated layout story (a ScrollableArea ref, Collapsible and TreeList opening and closing). Tests: an owner-set isOpen, a group's controlled value and isExpanded in items glide; one measurement in StrictMode and none for a refused change. * test(core): the adopters' browser spec serves Storybook through a11y-spec, a dependency core already has The interaction harness is not one of core's dependencies, so importing it broke the package typecheck. * fix(core): a TreeList row collapsing with an expanded child moves what follows once; the chevron drops its spring without a handle - A changed row inside another changed row (a child left expanded when its parent collapses) is not reported as its own change: only the outer group exits and gives up its space, the child's group leaves with it when that exit ends, and the content after them moves once, with no jump back (AST-105 FR3). - Without a handle, Collapsible's and TreeList's chevrons drop the spring a handle set, so they keep the theme's own turn (AST-105 FR2). - Tests: a nested collapse holds only the outer group (jsdom) and moves the rows after it once with no jump (real browser, the story's Photos with Trips open); removing the handle clears the chevron's spring. * docs(core): Collapsible FR10 and TreeList FR8 cite AST-108 FR4a for the chevron The chevron turning while the content glides is a coordinated pair: it derives its transition from the same springs.settle motion, as AST-108 FR4a (proposed) asks of coordinated animations. * feat(sandbox): Animated Layout Perf, a fullscreen page measuring useAnimatedLayout in a long list Cindy asked for a perf test of useAnimatedLayout for an item in the middle of a long list. The page follows Markdown Perf's layout: heading and description, a muted toolbar, a Run metrics card beside the output. A list of 1k, 5k or 10k rows (every row rendered, or a virtualized window) has a Collapsible in the middle that takes the list's handle; a run expands and collapses it six times and reports the commit and walk until the glide starts, rectangles read, elements animated, time to the first frame, long tasks, frames and drops, each against a saved baseline. Sandbox only: no package change. * fix(sandbox): Animated Layout Perf toggles only the middle item, so a run measures its commit and the walk, not a list re-render The open state lived on the page, so each toggle re-rendered every row (10k rows: most of the 275 ms). The middle item now owns it, and the rows are built once per list and window. * feat(sandbox): Animated Layout Perf compares a run without the handle, 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. * fix(sandbox): Animated Layout Perf keeps baselines across reloads, reports 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. * fix(sandbox): Animated Layout Perf charges the browser's layout to both 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. * Merge origin/main into feat/animated-layout-perf The base branches (#8482, #8568) merged to main as squashes, so every file they touched takes main's version, and their already-released changesets go. This PR's own three sandbox files are unchanged; the sandbox route list keeps main's new entry beside this page's. * sandbox(animated-layout-perf): show no long-task reading without the 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. * sandbox(animated-layout-perf): use the perf pages' existing format and 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.
User need
When something inside a scroll container or app panel changes size (a folder in a tree opens, a settings section expands), the content after it jumps to its new place. People lose their place in a list, on a phone and with a mouse alike. An app can't fix this by composition: the content after the change belongs to other components and the app's own elements, and none of them know a size change happened above them.
Problem and solution fit
useAnimatedLayout({containerRef})returns one opaque handle per area. A component whose size changes takes it and reports each change through it.useAnimatedLayouthook and Collapsible's and TreeList'sanimatedLayoutprop arrive together in feat(core): useAnimatedLayout, and Collapsible and TreeList glide the content after them (spec:AST-105) #8568, which is stacked on this one, so no public API ships before a component can take the handle.Current specification
spec:AST-105(current): FR1–FR7, Coverage and Verification.architecture:react-component-runtimeINV12: one internal module, a compositor-only translate (through the shared rectangle morph once Core has it; this module's own compositor translate until then, as amended here), a walk throughparentElement/nextElementSibling, and changes batched per area per frame.springs.settle(spec:AST-094FR4), read from the internal role registry. Roles are internal (spec:AST-094DEC-11): no theme, scope or custom property overrides it.design:reduced-motionDR1–DR3. This is a named fine-pointer change underspec:AST-017FR59 (spec:AST-105FR5).Public delta and caller burden
None: the module is internal and unexported, and no component uses it yet. The public hook and prop are in #8568.
Design and alternatives
animate()reports whether the change was measured, so a component lands an unmeasured change at once.playLayoutChange). Its exit (holdLayoutExit) keeps it where it is, in flow and inert, while it gives up exactly its space: the end margin is measured against the layout with the element taken out of flow (so CSS animations inside it keep running) and corrected for a scaled ancestor, so gaps and collapsing margins come out exact, and the content after it glides up at once while it still scrolls and clips with its container. It conceals upward on the same motion before the component hides it. Only a measured close is held. Where no margin can free the space (a grid item whose track or gap changes, or a flex-row item that sets its row's height), the element hides at once without its exit and the content after it takes its final place at once, as AST-105's out-of-coverage list now names. A changed element that an earlier change in the same frame displaced moves with its row, by its total change, and nested changes compose whichever is reported first.display: contents.transform,translate,rotateorscale, or a transform animation the module did not start) takes its final place at once.translate, which the compositor runs (INV12), sampled fromsprings.settleinto linear keyframes and corrected for a scaled ancestor. An element already gliding keeps that motion and adds the new move: the rest of its running curve and the new move are summed into one new glide, so it keeps its speed with no jump. Every animation of a change starts on the document timeline's current time. The glide, the entrance and the exit all read the one internalsprings.settlevalue. Height is never animated, and the area is never scrolled.spec:AST-105DEC-1): wrapping the following content in an element, or opting in each following element.Evidence
The module's proof is its real-browser spec (below): one case per
spec:AST-105Coverage row plus INV12's throttled-phone case, run in real Chromium. The fine-pointer before-and-after imagesspec:AST-105FR5 asks of adopting pull requests are on #8568 (Collapsible and TreeList, open and close).Scope
This introduces a new behavior module (
motion/animatedLayout.ts). The adoption is split into #8568.Testing
animatedLayout.test.ts(jsdom, 29 tests): the handle has no members; nothing runs without a handle; the walk at every level and nothing past the area;display: contents; absolute, fixed, hidden anddisplay: noneskipped; unchanged and out-of-view elements left alone; two changes in one frame move once by the total; the area is never scrolled; one duration fromsprings.settle, unchanged by a scope's--motion-springs-settle; Reduce Motion (a cross-fade on a coarse pointer, at once on a fine one); a running glide continued with its speed plus the new move; a refused measurement dropped by the next frame; an unmeasured change moving nothing; the exit kept in place, inert, giving up exactly its space (a gap included), landing at once where a grid track can't free it, refusing an unmeasured close, putting back the element's own inert and inline values, a refused hold keeping its own margin and gliding nothing, concealed, handed back, stopped by a reopen, and landing at once or fading under Reduce Motion; a changed element an earlier change displaced moving by its total change; an element not rendered before a change not moving; app-moved followers left alone.animatedLayout.boundary.test.ts: INV12's source boundary check (no layout property animated; the walk only throughparentElement/nextElementSibling, enteringdisplay: contentsalone; nothing public; nothing uses the module yet).animatedLayout.interaction.browser.spec.ts(the interaction proofs, Chromium and WebKit; run locally in real Chromium: 32 of 32 pass, three repeats): one case perspec:AST-105Coverage row (the sticky row with a stuck header after the change, the flex row with an item that wraps and a row-direction neighbor whose rectangle does not change); INV12's throttled-phone case (a 10-level by 50-sibling tree, two changes in one frame: one move per follower, none inside a subtree, none past the area, no height); FR2; FR3 (two changes in one frame, the displaced changed element included; scrolling identical with and without a handle); FR4 (one start frame and duration, the exit while the content after glides up, the exit in a scrolled area staying in place, scrolling and keeping its width, the exit freeing exactly its space in a flex gap, with collapsing margins, before adisplay: contentswrapper and as the last child of a plain wrapper (Collapsible's shape), a tall flex-row item refused with nothing gliding, nested changes reported inner-first, a gap stack under a scaled ancestor, a spinner inside the closing element keeping its time, app-moved followers left alone, a scope's--motion-springs-settlechanging nothing, Reduce Motion on each pointer); FR5.pnpm -F @astryxdesign/core typecheck, eslint,pnpm check:repo,pnpm check:knowledge; motion and hooks tests: 956 pass.Writing rubric results
Records touched:
architecture:react-component-runtimeINV12: the glide plays through the shared rectangle morph once Core has it, and its own compositor translate until then.spec:AST-105: one out-of-coverage line for a closing element whose space no end margin frees (a grid item whose track or gap changes, or a flex-row item that sets its row's height).Rubric:
animatedLayout.test.ts(the grid fallback and refused-hold cases) and the tall flex-row browser case.