Repository navigation
fix(core): a layout change made late in a long task plays its motion instead of skipping past it - #9274
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| AppShell · Storybook | 69.2 kB (+579 B) · 12.2 kB CSS (0) | 1,096 (+2) | ✗ · ✓ · ✓ |
| SideNav | 66.9 kB (+718 B) · 10.9 kB CSS (0) | — | ✓ · ✓ · ✓ |
| TreeList | 38.4 kB (+458 B) · 5.0 kB CSS (0) | — | — · — · — |
13 more components
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| Collapsible | 22.9 kB (+408 B) · 4.5 kB CSS (0) | — | — · — · — |
| PowerSearch | 185.9 kB (+396 B) · 20.6 kB CSS (0) | — | — · — · — |
| SegmentedControl | 82.2 kB (+3 B) · 7.8 kB CSS (0) | — | — · — · — |
| Switch | 87.3 kB (+2 B) · 10.6 kB CSS (0) | — | — · — · — |
| DateInput | 103.7 kB (0) · 15.3 kB CSS (0) | — | — · — · — |
| SideNavCollapseButton | 46.3 kB (0) · 9.8 kB CSS (0) | — | ✓ · ✓ · ✓ |
| SideNavHeading | 58.9 kB (0) · 10.6 kB CSS (0) | — | ✓ · ✓ · ✓ |
| SideNavItem | 54.9 kB (0) · 10.5 kB CSS (0) | — | ✓ · ✓ · ✓ |
| SideNavSection | 6.6 kB (0) · 3.7 kB CSS (0) | — | ✓ · ✓ · ✓ |
| TimeInput | 90.5 kB (0) · 14.3 kB CSS (0) | — | — · — · — |
| DateTimeInput | 159.7 kB (−2 B) · 17.1 kB CSS (0) | — | — · — · — |
| lab/MobilePowerSearch | 215.2 kB (−10 B) · 1.2 kB CSS (0) | — | — · — · — |
| Slider | 89.1 kB (−11 B) · 9.4 kB CSS (0) | — | — · — · — |
Visual changes: 2 snapshots in 1 component
A change is a question for the reviewer, not a failure.
| Component · story | Before | After | Diff |
|---|---|---|---|
| AppShell · Playground (neutral, dark) | ![]() |
![]() |
![]() |
| AppShell · Playground (neutral, light) | ![]() |
![]() |
![]() |
Package size: @astryxdesign/core 6.12 MB packed (+6.0 kB); no new dependencies.
API changes: none in this pull request
Committed API report behind this build: core 50 rows; run pnpm api:report.
Touched components checked; add ci:run-visual, ci:run-a11y or ci:run-rtl to run the full suites.
Generated by PR Enrichment workflow | View full report
There was a problem hiding this comment.
Requesting changes: the fix works on the page itself, since a layout change made after a long block now plays instead of finishing before the first frame, and the new browser case fails on main and passes here. Two things need fixing before it can merge:
startForcompares the globalperformance.now()with the element's own document timeline, so in a same-origin iframe or a Document Picture-in-Picture window every layout change starts in the future by the gap between the two documents' clocks and holds its old place (or stays at opacity 0 under Reduce Motion); read that document's ownperformance.now(), keep one shared start per document, and add a browser case with an iframe area.- The changeset and the comment in
safeAnimatesay the frame that draws the animations starts them, but the code starts them at the moment of the change; please reword both.
[Automated review]
|
|
||
| function startFor(frame: number): SharedStart { | ||
| if (sharedStart?.frame !== frame) { | ||
| const now = performance.now(); |
There was a problem hiding this comment.
This compares the page's clock with element.ownerDocument's timeline. In a same-origin iframe or a Document Picture-in-Picture window the two have different time origins, so every change there takes the late path and starts in the future by the gap: in Chromium, for an iframe made 2 s after the page loaded, the row after the change held its old place (or opacity 0 under Reduce Motion) for about 2 s. Read the clock of the document whose timeline you read (document.defaultView?.performance.now()) and keep one shared start per document, e.g. a WeakMap<Document, SharedStart>.
There was a problem hiding this comment.
Requesting changes: the per-document clock and the wording from the last round are fixed, and a layout change made after a long task now plays instead of skipping (the new browser cases fail on main, or with the page's clock, and pass here). One thing remains: the changeset and title say every late layout change now plays, but startFor shares one start per frame time, so a change made after a block that follows an earlier layout motion in the same task still starts on the pre-block frame and is over by the first frame, as on main; please word the changeset and title to match, or cover that case with a browser test. Separately and not blocking, reportLayoutEdge's measureBefore could clamp the running reveal's time at 0 like the other readers, since a late start makes it negative for the rest of its task.
[Automated review]
| '@astryxdesign/core': patch | ||
| --- | ||
|
|
||
| [fix] A layout motion made late in a long main-thread task, such as a tap on a slow device, now plays instead of being skipped: under Reduce Motion the side navigation rail's cross-fade showed no fade at all after such a block. A layout change's animations start on the frame time the page last read only while that frame is at most 34 ms old; otherwise they start at the moment the change is made, so the block delays the motion and every part of the change still starts together. |
There was a problem hiding this comment.
This promises every late layout change now plays, but startFor shares one start per frame time: once one layout motion of a task has started near its frame (playLayoutChange and playLayoutEdge take the start synchronously), a change made later in that task, after a block, reuses that pre-block start. In a Chromium probe, a second change made after a 1 s block started on the old frame time and was finished two frames later, as on main. Suggested wording: "…now plays instead of being skipped, unless an earlier layout motion of the same task started before the block. Every layout animation made while the page reads one frame time shares one start: that frame time if the first of them came within 34 ms of it, otherwise the moment the first was made."
06f8ad7 to
90ba1b1
Compare
|
Addressed in 90ba1b1, rebased onto main 5909b93:
|
90ba1b1 to
c6887ab
Compare
|
Addressed in c6887ab:
|
There was a problem hiding this comment.
Requesting changes: a layout change made after a long task now plays instead of skipping (the new browser cases fail on main and pass here), and the two items from the last round are fixed. One regression remains: startFor groups animations by the gap between them, so a change's entrance (played in the adopter's layout effect) and its followers' glide (made after the commit) take different starts whenever the rest of the commit runs longer than 34 ms, and the revealed edge runs ahead of the row after it, up to 47 px with 60 ms of work in Chromium, where main keeps one start. Please tie the shared start to the change rather than to the gap between animations, and add a browser case with more than 34 ms of work between playLayoutChange and the flush.
[Automated review]
| if ( | ||
| start != null && | ||
| start.frame === frame && | ||
| now - start.last <= LATE_START_MS |
There was a problem hiding this comment.
Grouping by the gap between two animations splits one change: an adopter plays the entrance in its layout effect (Collapsible.tsx:425-430) and the batch makes the followers' glide in a microtask after the whole commit, so any commit work over 34 ms in between gives the glide a fresh start. In Chromium, 60 ms of work after playLayoutChange put the entrance at 30.6 ms and the glide at 96.2 ms, and the revealed edge ran up to 47 px ahead of the row after it (main: one start, 0 px). Tying the start to the change (for example, deciding it when animate() queues the area's batch and handing it to that change's entrance, exit or edge) would keep both block cases working.
c6887ab to
c2b0cbb
Compare
|
Addressed in c2b0cbb: the shared start is now tied to the change rather than to the gap between animations.
|
There was a problem hiding this comment.
Requesting changes: a layout change made after a long task now plays instead of skipping, the new browser cases pass in Chromium and WebKit, and last round's entrance/glide split under 60 ms of commit work is fixed. One regression remains: the shared start lives in one slot per document, so when a second change begins after a block before the first change's glide flush has run (the case at animatedLayout.interaction.browser.spec.ts:803, with nothing run between them), beginChange replaces it and the first change's glide starts about 1 s after its own entrance, leaving its rows over the revealed content for the whole glide. Please capture the start for each change and hand it to that change's flush and riding parts, and assert in that case that the first change's glide starts with its entrance.
[Automated review]
| const held = changeStarts.get(doc); | ||
| if (held != null && clockOf(doc) - held.last > LATE_START_MS) { | ||
| changeStarts.delete(doc); | ||
| } |
There was a problem hiding this comment.
When a second change begins here after a block, before the first change's glide flush (queued at line 1257) has run, the slot is emptied and the second change refills it, so the first change's glide takes the second change's start while its entrance keeps the earlier one. With the fixture of the case at animatedLayout.interaction.browser.spec.ts:803, the first change's entrance starts at about 25 ms and its glide at about 1,040 ms (Chromium 3 of 3; WebKit 28 vs 1,039 ms), and two frames after the block its rows cover the 120 px of revealed content. Capturing the start for the change (when animate() schedules the area's flush, or at its first animation) and handing it to that flush and the parts riding its glide would keep both block cases working.
c2b0cbb to
8ba5b7d
Compare
|
Addressed in 8ba5b7d, rebased onto current
|
There was a problem hiding this comment.
Recommending approval: a layout change made late in a long task now plays instead of finishing before the first frame, and last round's two-state reversal gap is fixed. The side navigation rail's edge now stays on the content when a reversal follows a block, and the new browser case catches the old 104.3 px gap; the block cases fail on main and pass here in Chromium and WebKit, and under Reduce Motion the rail's cross-fade now plays after a long tap.
- Optional: the
animatedLayout.tsfile header this pull request edits runs about 78 lines; keeping@outputto the export list would match the comment guideline.
[Automated review]
| * `spec:AST-105` defines (`architecture:react-component-runtime` INV12) | ||
| * internal `springs.settle` motion role (motion/roles.ts), the Reduce Motion | ||
| * cross-fade clock (uikit/timing.ts) and the block measure (frameBlock.ts) | ||
| * @output Exports `createAnimatedLayout`, the opaque `AnimatedLayout` handle, |
There was a problem hiding this comment.
Non-blocking: this header now runs from line 3 to line 81, and the comment guideline keeps @input, @output and @position to about 12 lines. Keeping @output to the export list, and moving the "How it works" list to the motion README, would fit it.
d88b8aa to
3ff634d
Compare
|
/approve-spec 3ff634d |
There was a problem hiding this comment.
Requesting changes. The late-start fix works: the three block cases fail on main and pass here, the module and rail browser specs pass in Chromium, and the new component:SideNav FR6 sentence on the initial state has an engineering owner's approval for this head. Three things need fixing before it can merge:
frameTimeOfsits between SideNav's JSDoc block andexport function SideNav(SideNav.tsx:459-466), so the exported component loses its documentation and@examplein editors and the emitted types; move the helper above that JSDoc block.- The new
useLayoutEffectatSideNav.tsx:555-557only records the timeline's frame when the nav attaches; record it from a callback added to the nav's existing merged ref (SideNav.tsx:508) and remove the Effect. - In the rail's mount frame the head lands AppShell's content area too, but
component:AppShellFR17 still says the content swaps on every collapse or expand; add the same initial-state sentence to FR17 in this pull request.
Non-blocking: the comment at SideNav.tsx:532 still says every collapse or expand plays the rail's motion.
[Automated review]
| * ``` | ||
| */ | ||
|
|
||
| /** The frame time a document's timeline reads, or null without one. */ |
There was a problem hiding this comment.
This helper now sits between SideNav's JSDoc block (lines 441-458) and export function SideNav, so TypeScript attaches that block to nothing and the exported component loses its description and @example in editors and in the emitted declaration. Move frameTimeOf above the JSDoc block.
| useLayoutEffect(() => { | ||
| mountFrameRef.current = frameTimeOf(navRef.current?.ownerDocument); | ||
| }, []); |
There was a problem hiding this comment.
This Effect only records the timeline's frame when the nav element attaches. A callback added to the existing merged nav ref (useMergedRefs(ref, navRef, modalityRef), line 508) can record it at attachment, which also follows a replaced nav node; then this Effect can go.
3ff634d to
432cb9d
Compare
|
/approve-spec 432cb9d |
There was a problem hiding this comment.
Requesting changes. The late-start fix works: after a slow click the side navigation rail's collapse, and its Reduce Motion cross-fade, now play instead of skipping, the module's browser spec passes in Chromium, its block and two-state cases pass in WebKit, and last round's three items are fixed. One thing needs fixing before it can merge:
recordMountFrame(SideNav.tsx:514-518) records the frame on every attach of the merged nav ref, and an inline callbackrefon SideNav re-attaches it on every re-render, so a collapse the app makes in a later commit of that frame, after the rail has painted, lands with no motion (0 animations against 9 onmain); record the frame only when the attached node changes, and add an inline-ref case toSideNavRailMotion.test.tsx.
Non-blocking: the animatedLayout.ts file header still runs about 78 lines, and the JSDoc on frameTimeOf restates its name and return type.
[Automated review]
| const recordMountFrame = useCallback((nav: HTMLElement | null) => { | ||
| if (nav != null) { | ||
| mountFrameRef.current = frameTimeOf(nav.ownerDocument); | ||
| } | ||
| }, []); |
There was a problem hiding this comment.
This runs on every attach of the merged ref, and useMergedRefs makes a new merged callback whenever ref changes identity. With an inline ref={node => …} on SideNav, each re-render re-attaches the nav and records the current frame, so an app collapse in a later commit of the same frame (after the rail has painted) matches the check at line 577 and lands with no motion: 0 animations in a probe, against 9 on main and 9 with a stable ref. Recording only when the attached node differs from the last one recorded keeps the initial-state cases passing and plays the change.
…ref test case and its story)
432cb9d to
a3b1fb7
Compare
|
/approve-spec a3b1fb7 |
There was a problem hiding this comment.
Requesting changes. The late start fixes the skipped rail collapse and the skipped Reduce Motion cross-fade after a slow tap, and the inline-ref guard keeps later changes animated. One reversal path still mixes two clocks.
Blocking
- A rail toggle that reverses a running collapse after a long task restarts the content area's cross-fade and the rail copy's fade from their pre-block progress while the glide carries on from where the compositor has it (
AppShell.tsx:1000-1004,animatedLayout.ts:2614), so read that progress at the change's start asflushdoes withchange.at(in AppShell,layoutStartFor(main.ownerDocument) - last.startedAt) and add a browser case for a second toggle after a block.
Non-blocking
- The
component:AppShellFR17 verification row creditsSideNavRailMotion.interaction.browser.spec.tswith the before-first-paint case, which only the unit test covers.
[Automated review]
| const elapsed = Math.max( | ||
| 0, | ||
| Number(main.ownerDocument.timeline?.currentTime ?? 0) - | ||
| last.startedAt; | ||
| last.startedAt, | ||
| ); |
There was a problem hiding this comment.
This progress is read on the timeline's held frame, but the glide this change retargets carries on from the compositor's time at the change's start (animatedLayout.ts:1212-1216). After a block the two disagree: a collapse, then an expand 150 ms later behind 1 s of click-handler work, starts the collapsed text's copy at 0.73 and the expanded text at 0.27, although the collapse had ended by then (a settled reversal starts at 0.93 and 0.07). Reading layoutStartFor(main.ownerDocument) - last.startedAt here gives 0.96 and 0.04 for the same reversal and leaves a reversal without a block unchanged (0.71 and 0.29).
| motion.kind === 'spring' ? motion.progress.durationMs : motion.durationMs; | ||
| const shown = (): {extent: number; progress: number} | null => { | ||
| const elapsed = now() - startedAt; | ||
| const elapsed = Math.max(0, now() - startedAt); |
There was a problem hiding this comment.
The rail's fades take their progress from this shown(), read on the timeline's held frame. In the same reversal after a block, the rail's held copy starts at 0.18 where a settled reversal starts at 0.89, so the rail's icons flash back while its edge rides on. Reading the progress at the change's start, as the glide does, keeps the reversal from the shown state (spec:AST-105 FR9).
| * `playLayoutEdge`), `playLayoutFrames` and `applyLayoutChangeTransition`: | ||
| * the one module that produces the size-change glide and the edge reveal | ||
| * `spec:AST-105` defines (`architecture:react-component-runtime` INV12) | ||
| * internal `springs.settle` motion role (motion/roles.ts), the Reduce Motion |
There was a problem hiding this comment.
Non-blocking (INV29): this header still runs from line 3 to line 81, against about 12 lines. Keep @output to the export list and move the "How it works" list to the motion README.
…instead of skipping past it The layout module started every animation of a change on the document timeline's current time, so a retargeted glide keeps moving through the frame it is replaced in and a change's animations share one start. Chromium holds that time at the frame before a long task once anything in the task reads it, so a change made late in such a task started in the past: the first frame after the block showed it skipped into its curve, or past all of it. After a 1 s tap task on a slow device, the side navigation rail's Reduce Motion cross-fade never showed. The module now starts a change on the timeline time only while that frame is at most LATE_START_MS old. Otherwise its animations start together at the moment the change makes its first one, and hold their first keyframe until the timeline gets there, so the block delays the motion instead of skipping it. A change keeps one start from its first animation (the changed element's own entrance, say) through the flush of its glides and the parts that ride them, played in the microtasks after it, however long the rest of the commit runs: the start holds through the task that made it. A change that begins (its "before" read) after a block since the last layout motion takes a fresh start, so a change made after a block that follows an earlier layout motion in the same task plays too. Each change keeps the start it took, in its glide batch and in the parts it plays later in the task, even when another change begins after a block before its glides flush; a change that begins in the same area before those glides flush joins that change and its start. A glide such a change retargets carries on from where the compositor has it at the change's start, rather than from the frame the timeline held through the block. The parts that ride such a glide, as the side navigation rail's two-state edge does, ride it from where it showed when they were read, so they move with the content instead of parting from it by the block's drift. The edge reveal's own progress (the rail's width) and AppShell's swap follow a change on the start the module gives it (layoutStartFor) instead of the timeline time at the change. Each document keeps its own start, on its own clock, so a change in an iframe is not dated by the page's. The animator's block measure moves to motion/frameBlock.ts, which both read. The side navigation's initial state never animates: a collapse or expand made before the rail first paints, other than by the rail's own toggle, lands at once with the content. Until a frame runs after the rail mounts, the document timeline reads the frame it read at the mount, so the rail compares the two. The mount frame is read once per nav node, so an inline ref that re-attaches the nav on each render does not restart it. Before this change, a state an app restores during a long load task would have glided once that task ended. A riding edge's `shown()` now reads the ridden element where its glide shows on the timeline's clock, from the glide's own curve. WebKit evaluates a running translate on the live clock after a block, while the timeline still reads the frame before it, so a reversal read late in its task started the edge ahead of or behind the content. The two reads now agree in every engine. After a long task, a reversal's fades start from the progress at the change's start, where the glide it retargets carries on: the content area's cross-fade in AppShell and the rail copy's fades through the edge's `shown()`. The riding edge's extent stays on the timeline's frame, the frame its ride is measured from.
a3b1fb7 to
5ce160e
Compare
|
/approve-spec 5ce160e |
There was a problem hiding this comment.
Recommending approval: after a slow tap, the side navigation rail's collapse and its Reduce Motion cross-fade now play instead of finishing before the first frame, and a reversal after a long task starts its fades from what the page shows.
- A reversal after a long task now starts the content area's cross-fade and the rail's fades from the change's start, and the new browser case fails without that fix.
- The new initial-state requirement in
component:SideNavFR6 andcomponent:AppShellFR17 has an engineering owner's approval on this head. - Non-blocking: the
animatedLayout.tsfile header still runs about 79 lines; trimming@outputto the export list would bring it near the comment guideline.
[Automated review]
| * `spec:AST-105` defines (`architecture:react-component-runtime` INV12) | ||
| * internal `springs.settle` motion role (motion/roles.ts), the Reduce Motion | ||
| * cross-fade clock (uikit/timing.ts) and the block measure (frameBlock.ts) | ||
| * @output Exports `createAnimatedLayout`, the opaque `AnimatedLayout` handle, |
There was a problem hiding this comment.
Non-blocking: this file header still runs from line 3 to line 81, against the comment guideline's "about 12 lines". Keep @output to the export list and move the "How it works" list to the motion README.






User impact
On
main, a layout change made late in a long task (a slow click handler) skips its motion: the side navigation's collapse snaps to its end, and under Reduce Motion its cross-fade never shows.Problem and solution fit
LATE_START_MS), else when its first animation is made; its glides and riding parts share that start.Expected behavior and authority
A block delays motion, never skips it (
motion/README.md,design:reduced-motionDR2).component:SideNavFR6 andcomponent:AppShellFR17 gain the initial-state sentence.Smallest restoration
One start rule per change in
safeAnimate; rides read the ridden glide's curve; SideNav compares the timeline's frame with its mount frame.Evidence
main's module, 4 of the animated-layout spec's 84 Chromium cases fail (the block cases); the rail's slow-CPU Reduce Motion case fails 5 of 30. On not-for-landing red arms, the initial-state case fails 3 of 3 (e33222f), the inline-refcase fails (36bec5c), a reversal read late in its task fails in WebKit 5 of 5 (8ce9bb9), and one after a 1 s task starts its fades at 0.62/0.38/0, not 1/0/1 (91eed12).refcase; WebKit 20 of 20; the two reversals match, 5 of 5.Scope
Writing rubric results
R1 narration: none; present tense. R2 research: none. R3 evidence: both verification rows name cases. R4 rejected alternatives: none. R5 change references: none. R6 open questions: none.
Testing
Code Quality's desktop recording at 5ce160e: Chromium passes all four conditions; the inline-ref collapse glides; WebKit shows no trail. In the reversal after a long task the fades stay in sync with the glide, and the rail's edge catches up in one frame (about 100 px), less than
main's full skip.Recording story:
Core/SideNav› Inline ref collapse (core-sidenav--inline-ref-collapse): an inlinerefand a button that renders the nav again, then collapses it in a later commit of the same frame.The
mainarm is 1bd5870 (not for landing:main3615956 plus this branch's animated-layout spec): 80 passed and 4 failed in Chromium, against 84 of 84 here. At this head, on one box: install, build, Storybook build, SideNav's accessibility contract (3 of 3), the module's, adopters', rail and AppShell browser specs pinned in Chromium (103 of 103) and in the CI WebKit container (92 passed, 11 skipped, 0 failed), the reversal case in WebKit 20 of 20,test:ui(19,123),check:knowledge, changesets,review:preand lint (0 errors) all pass. The node suites pass at this head (16,120). At the previous head, 4 CLI integration files timed out under box load; this pull request touches no CLI code, and they passed onmainand on that head when run again at one moment.