Skip to content

fix(core): the animator rechecks a finished animation's end in frame callbacks from a frame before it - #9285

Merged
cixzhang merged 1 commit into
meta:mainfrom
vjeux:uikit/f1-animator-retire-at-frame
Nov 1, 2026
Merged

cixzhang merged 1 commit into
meta:mainfrom
vjeux:uikit/f1-animator-retire-at-frame

Conversation

@vjeux

@vjeux vjeux commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

User impact

This is a product-side timing change in the touch presentations' animator, not a test change. When a motion ends, the animator drops its animation and writes the end value inline. That drop ran on a timer at the curve's end; the animation's own time moves only at frames, so under load the timer could land between two frames, find the time a fraction short, and look again a frame later. The animation then stayed on the element for one or two frames past its curve. The animator is internal and not yet used by a shipped component, so no consumer sees it today; every touch component built on it would.

Problem and solution fit

  • Why it lingers. No browser event reports that an animation's time has reached a point inside its effect, so the animator looks at the curve's end on a timer, and when the time is short of it by less than a frame, looks again on another timer. A loaded main thread runs timers late and between frames.
  • The fix. A timer a frame before the curve's end starts a recheck in frame callbacks: each frame callback looks again while up to two frames remain (the frame it runs in can be dated before that timer was due), and the first one whose frame time reaches the end retires the animation, before that frame paints. Only a timer running more than a frame late can still leave the animation on for one frame past its end, which the proof allows. The timers stay as the fallback for a page that draws no frames, such as a hidden tab.

Expected behavior and authority

The animator's retire contract: a finished animation leaves the element once the curve ends, with its end value inline (the animator's header, "retiring"). The proof "a finished animation leaves the element once the curve ends" requires it gone by the second frame at or after the end.

Smallest restoration

Within the animator's scheduleRetire: a look in the next frame callback when the time is short of the end by less than a frame (by less than two frames from a look already in a frame callback), and a timer a frame early that starts those looks. The timers, their constants and every other path are unchanged; dispose clears the new timer and looks with the others.

Evidence

  • Reproduction before the change (main): the proof fails 7 of 120 runs in Chromium pinned to 2 cores at 4 workers: the animation is still on the element in the first two frames at or after the curve's end. The updated unit case "looks for its end again on the next frame when the engine dates animations per frame, not in a spin, and retires in that frame" fails on main.
  • Result after the change: the proof passes 200 of 200 at that load at this head (main, run alongside on the same base: 13 of 200 failed); the unit case passes.
  • A look in a frame dated short of the end: the unit case "keeps looking while the frame it looked in was dated short of the end, and retires in the frame that reaches it, before a late end timer runs" fails on the previous revision, where that look requested no further frame and a late end timer decided; it also fails with the early look timer removed.
  • Representative unchanged path: the animator's whole browser spec passes ×10 in Chromium pinned to 2 cores at 1 worker (170) and ×10 under the CI WebKit job's command (130, with 40 Chromium-only skips); the motion and hooks unit suites pass (1,299).

Status at this head: every gate has finished. Build, type check, lint, check:knowledge, check:changesets, test:ui (17,393) and check:repo pass; the node suites fail only the two cache.test.mjs lock cases that fail on main. The animator spec passes in Chromium pinned to 2 cores at 1 worker ×3 (51) and under the CI WebKit job's command ×10 (130, with 40 Chromium-only skips). Under that command at 4 workers, a load CI does not run, the proof fails 4 of 200 runs (main 13 of 200): in each, the timer that starts the frame looks ran more than 20 ms late, after the first frame past the end had begun.

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Testing

pnpm exec vitest run --project ui packages/core/src/motion/animator.test.ts
pnpm test:interaction packages/core/src/motion/__tests__/animator.interaction.browser.spec.ts --project chromium --workers=1

For WebKit, use the CI WebKit job's container command (internal/interaction-harness/scripts/webkit-container.mjs) with podman --cpus=4, CI=1, LP_NUM_THREADS=4 and 1 worker.

@vjeux
vjeux force-pushed the uikit/f1-animator-retire-at-frame branch from 15c5e8b to e7b7445 Compare November 1, 2026 09:09
@vjeux

vjeux commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

Addressed in e7b7445: the title, changeset and description now describe the frame-callback recheck that a timer starts a frame before the curve's end, and say that a timer running more than a frame late can still leave the animation on for that frame; "keeping it promoted" is gone from the description.

The non-blocking note on retireFrames is right: a look still pending from a replaced animation can swallow the next animation's first look, which then falls back to the timer, as before this change. Keying the pending looks by animation closes it; that is a small follow-up, kept out of this head.

@vercel

vercel Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 1, 2026 12:22pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 1, 2026
@astracat-bot

astracat-bot Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 1, 2026, 12:28 PM UTC

@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 4b346ad

Storybook · Sandbox · built from this PR's head

Package size: @astryxdesign/core 5.66 MB packed (+1.1 kB); no new dependencies.

API changes: core +8 · ~20 · −0 (report stale: run pnpm api:report); richtext +0 · ~1 · −0 (report stale: run pnpm api:report)

29 API changes (advisory)
Package Where Signature Usage
+ core . · Types · interface FieldStatusProps message: string import type {FieldStatusProps} from '@astryxdesign/core'; const x: FieldStatusProps = {message: …}
+ core . · Types · interface FieldStatusProps ref?: React.Ref<HTMLDivElement> import type {FieldStatusProps} from '@astryxdesign/core'; const x: FieldStatusProps = {ref: …}
+ core . · Types · interface FieldStatusProps type: InputStatusType import type {FieldStatusProps} from '@astryxdesign/core'; const x: FieldStatusProps = {type: …}
+ core . · Types · interface FieldStatusProps variant?: FieldStatusVariant = 'attached' import type {FieldStatusProps} from '@astryxdesign/core'; const x: FieldStatusProps = {variant: …}
+ core . · Types · interface FieldStatusProps xstyle?: StyleXStyles import type {FieldStatusProps} from '@astryxdesign/core'; const x: FieldStatusProps = {xstyle: …}
+ core . · Types · interface FieldStatusProps inherits AriaAttributes, DOMAttributes, HTMLAttributes import type {FieldStatusProps} from '@astryxdesign/core'
+ core . · Types · interface SearchContext interface SearchContext<T extends SearchableItem = SearchableItem> import type {SearchContext} from '@astryxdesign/core'
+ core ./Typeahead · Also exported from an earlier entry point · SearchContext SearchContext (.) import {SearchContext} from '@astryxdesign/core/Typeahead'
~ core . · Components · component ComplexSelector prop statusVariant?: FieldStatusVariant = 'attached' for input selectors; 'detached' for secondary and ghost selectors → prop statusVariant?: FieldStatusPlacement = 'attached' for input selectors; 'detached' for secondary and ghost selectors <ComplexSelector statusVariant="attached" />
~ core . · Components · component DateInput prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' <DateInput statusVariant="attached" />
~ core . · Components · component DateRangeInput prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' <DateRangeInput statusVariant="attached" />
~ core . · Components · component Field prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' <Field statusVariant="attached" />
~ core . · Components · component FieldStatus component FieldStatus(props: FieldStatusProps) → component FieldStatus @deprecated <FieldStatus />
~ core . · Components · component FieldStatus prop variant?: FieldStatusVariant = 'attached' → prop variant: FieldStatusVariant = 'attached' <FieldStatus variant="attached" />
~ core . · Components · component FileInput prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' <FileInput statusVariant="attached" />
~ core . · Components · component MultiSelector prop statusVariant?: FieldStatusVariant = 'attached' for input selectors; 'detached' for secondary and ghost selectors → prop statusVariant?: FieldStatusPlacement = 'attached' for input selectors; 'detached' for secondary and ghost selectors <MultiSelector statusVariant="attached" />
~ core . · Components · component NumberInput prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' <NumberInput statusVariant="attached" />
~ core . · Components · component PowerSearch prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' <PowerSearch statusVariant="attached" />
~ core . · Components · component Selector prop statusVariant?: FieldStatusVariant = 'attached' for input selectors; 'detached' for secondary/ghost selectors → prop statusVariant?: FieldStatusPlacement = 'attached' for input selectors; 'detached' for secondary/ghost selectors <Selector statusVariant="attached" />
~ core . · Components · component TextArea prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' <TextArea statusVariant="attached" />
~ core . · Components · component TextInput prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' <TextInput statusVariant="attached" />
~ core . · Components · component TimeInput prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' <TimeInput statusVariant="attached" />
~ core . · Components · component Tokenizer prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' <Tokenizer statusVariant="attached" />
~ core . · Components · component Typeahead prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' <Typeahead statusVariant="attached" />
~ core . · Types · interface FieldStatusProps interface FieldStatusProps extends BaseProps<HTMLDivElement> (props of FieldStatus) → interface FieldStatusProps extends BaseProps<HTMLDivElement> import type {FieldStatusProps} from '@astryxdesign/core'
~ core . · Types · interface FieldStatusVariantMap tooltip: true → tooltip: true @deprecated import type {FieldStatusVariantMap} from '@astryxdesign/core'; const x: FieldStatusVariantMap = {tooltip: …}
~ core . · Types · interface SearchSource search: (query: string) => Promise<T[]> | T[] → search: (query: string, context?: SearchContext<T>) => Promise<T[]> | T[] import type {SearchSource} from '@astryxdesign/core'; const x: SearchSource = {search: …}
~ core . · Types · interface UseInputStatusIconOptions statusVariant?: FieldStatusVariant → statusVariant?: FieldStatusPlacement import type {UseInputStatusIconOptions} from '@astryxdesign/core'; const x: UseInputStatusIconOptions = {statusVariant: …}
~ richtext . · Components · component RichTextEditor prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusVariant | 'tooltip' = 'attached' <RichTextEditor statusVariant="tooltip" />

Not run on this PR: add ci:run-visual, ci:run-a11y or ci:run-rtl to run them.


Generated by PR Enrichment workflow | View full report

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes for wording only; the code fix looks sound, and its updated unit case fails on the base animator and passes here. The title and changeset say a finished animation retires "in the first frame that reaches its curve's end", but the frame looks are started by a timer one frame early, so a timer that runs more than a frame late still leaves the animation on for that frame (the browser proof also allows one such frame). Please reword them to describe the frame-callback recheck that starts a frame before the end, and drop "keeping it promoted" from the description, since will-change stays for 500 ms past the curve either way.

[Automated review]

Comment thread .changeset/animator-retire-at-frame.md Outdated
'@astryxdesign/core': patch
---

[chore] Internal: the touch presentations' animator retires a finished animation in the first frame that reaches its curve's end, looking in frame callbacks from a frame before it, instead of on a timer that a loaded page can run a frame or two late. The timers remain for a page that draws no frames. Not exported from the package entry point.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"In the first frame that reaches its curve's end" is stronger than the mechanism. The frame looks start from the retireLooks timer one frame before the end (animator.ts:1467-1476), so a timer that runs more than a frame late still lets that frame paint with the animation on. The browser proof also accepts one present frame. Suggested: "…retires a finished animation from frame callbacks that start a frame before its curve's end, instead of re-arming a timer when its time reads a fraction short…".

// past its curve. The timers stay, for a page that draws no frames (a
// hidden tab).
const lookAtFrame = () => {
if (requestFrame == null || retireFrames.has(channel)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: retireFrames is keyed by channel, and neither rebuild nor scheduleRetire clears it. A look still pending from a replaced animation makes the new animation's first look return here, and that pending callback then exits at the running.get(channel) !== animation check. It only matters for a new curve that ends within about a frame of a retarget, which falls back to the timer, but keying the pending set by animation would close it.

@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 1, 2026
@cixzhang
cixzhang marked this pull request as ready for review November 1, 2026 09:46
@vjeux vjeux changed the title fix(core): the animator retires a finished animation in the first frame that reaches its curve's end fix(core): the animator rechecks a finished animation's end in frame callbacks from a frame before it Nov 1, 2026
@cixzhang cixzhang closed this Nov 1, 2026
@cixzhang cixzhang reopened this Nov 1, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes: the frame-callback recheck works in the common case, and the updated unit case fails on the base animator and passes here, but the chain of frame looks stops after one look whenever that look's frame is dated before the look timer was due, because retire(true) then reads more than END_RECHECK_MS left and requests no further frame (animator.ts:1414). In that case a slightly late end timer again decides the end frame, as on the base.

  • Let a frame callback keep looking while up to two frames are left, for example remaining <= (atFrame ? 2 : 1) * END_RECHECK_MS.
  • Add a unit case where the end timer runs after the frame that reaches the end: deleting the early look timer currently leaves the whole animator suite green.
  • Qualify the changeset's "so the frame that reaches the curve's end drops the animation before it paints" for a timer that starts the looks more than a frame late.

[Automated review]

Comment thread packages/core/src/motion/animator.ts Outdated
),
);
const paused = animation.playState === 'paused';
if (!paused && remaining <= END_RECHECK_MS) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a frame callback this gate ends the chain when the frame is dated before the look timer's due time (a frame already in flight, or the timer firing early because setTimeout truncates its fractional delay): the first look reads a little more than END_RECHECK_MS left and requests nothing, so the end frame falls back to the end timer. With the frame dated 3 ms early and the end timer 14 ms late, the animation is still on in the frame that reaches the end, as on the base. Widening it in the frame path, e.g. remaining <= (atFrame ? 2 : 1) * END_RECHECK_MS, fixes that and keeps the animator suite green.

flushReleases();
};
retireTimers.set(channel, setTimeout(retire, Math.max(0, end - now())));
if (requestFrame != null) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing tests this early look timer: deleting this block still passes all 196 animator unit cases, and the browser proof allows the end frame. A case where the end timer runs after the frame that reaches the end fails on the base and without this block, and passes here; please add it.

Comment thread .changeset/animator-retire-at-frame.md Outdated
'@astryxdesign/core': patch
---

[chore] Internal: the touch presentations' animator rechecks a finished animation's end in frame callbacks, starting a frame before it, instead of only on timers that a loaded page can run a frame or two late, so the frame that reaches the curve's end drops the animation before it paints. The timers remain for a page that draws no frames. Not exported from the package entry point.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"So the frame that reaches the curve's end drops the animation before it paints" holds only when the timer that starts the looks runs less than a frame late, which this same sentence says a loaded page does not guarantee. Suggested ending: "…drops the animation before it paints, unless the timer that starts the looks runs more than a frame late."

…callbacks from a frame before it

The animator drops a finished animation, writing its end value inline,
when a timer at the curve's end finds the animation's own time there. The
animation's time moves only at frames, so under load the timer could land
between two frames, find the time a fraction short, and look again a frame
later: the animation stayed on the element for one or two frames past its
curve (the retire proof failed 7 of 120 runs in Chromium pinned to 2 cores
at 4 workers). Now a timer a frame before the end starts a recheck in frame
callbacks, which keeps looking while up to two frames remain (the frame it
runs in can be dated before that timer was due), and the first frame
callback whose time reaches the end drops the animation before that frame
paints; only a timer running more than a frame late can still leave it on
for one frame. The timers stay as the fallback for a page that draws no
frames.
@vjeux
vjeux force-pushed the uikit/f1-animator-retire-at-frame branch from e7b7445 to 4b346ad Compare November 1, 2026 12:13
@vjeux

vjeux commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

Addressed in 4b346ad:

  • The frame-look chain no longer stops after one look when that frame is dated before the look timer was due: a look from a frame callback keeps looking while up to two frames remain (remaining <= (atFrame ? 2 : 1) * END_RECHECK_MS), so the next frame, which reaches the end, retires the animation before it paints.
  • New unit case, "keeps looking while the frame it looked in was dated short of the end, and retires in the frame that reaches it, before a late end timer runs": the look's frame is dated 20 ms short of the end and the end timer has not run when the next frame reaches it. It fails on the previous head, and also with the early look timer removed (which left the suite green before).
  • The changeset now says the frame that reaches the curve's end drops the animation before it paints "unless the timer that starts those rechecks itself runs more than a frame late".

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommending approval: a look from a frame callback now keeps going while up to two frames remain, and the new unit case fails on the earlier animator, without the early look timer, and with the one-frame gate, so each part of the fix is protected. One non-blocking follow-up remains, as you noted: retireFrames is keyed by channel, so a look still pending from a replaced animation can swallow the next animation's first look, and keying the pending looks by animation would close it.

[Automated review]

@cixzhang
cixzhang merged commit 70cef45 into meta:main Nov 1, 2026
54 checks passed
@vjeux
vjeux deleted the uikit/f1-animator-retire-at-frame branch November 1, 2026 13:01

This branch was successfully deployed

1 active deployment
Preview — 4b346add Deployed Nov 1, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants