Skip to content

refactor(motion): core's shared theme-timing reader - #10068

Merged
cixzhang merged 2 commits into
meta:mainfrom
vjeux:uikit/c21-theme-timing
Nov 5, 2026
Merged

cixzhang merged 2 commits into
meta:mainfrom
vjeux:uikit/c21-theme-timing

Conversation

@vjeux

@vjeux vjeux commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer impact

Ten open pull requests each carry a copy of a theme-timing reader, and SegmentedControl has a private one. Two readers disagree on a hand-written calc() token: a computed transition resolves it, and a token read falls back. This adds one shared reader. SegmentedControl uses it, and the open pull requests move onto it.

Intended invariant

A motion's timing is the theme's duration and easing, resolved where the element is:

What the reader does Merged record
Reads the duration and easing where the element is, so a theme scope and tempo apply spec:AST-094 FR45; spec:AST-108 FR2; spec:AST-090 FR2 ("The durations resolve like any token")
A token with no value there reads core's declared default, whose references resolve there too spec:AST-108 FR2's released values (durationDefaults, easeDefaults)
SegmentedControl keeps its segments' --duration-fast and --ease-standard component:SegmentedControl FR9

The default only applies without core's stylesheet, which gives every token a value. A zero, empty or unparseable value gets no rule: the reader returns no value, and the caller keeps its own behavior. SegmentedControl's lens lands at once, as before.

Change

  • motion/themeTiming.ts: resolveTiming resolves a CSS duration and easing as a transition does. Text such as calc() resolves on a hidden probe's transition. readThemeTokens reads theme tokens where an element is. readThemeTiming builds the eased progress from those tokens, or from the element's own transition.
  • SegmentedControl drops its private themeTimingOf and timedCurve for these.

Evidence

  • Failure before the change: for --duration-fast: calc(0.1s * 2), SegmentedControl reads 200 ms and a token reader 175 ms. A reader that parses token text, as the copies do, fails the reader's calc() browser cases (not-for-landing 5fbdda3b66).
  • Success after the change: both patterns read 200 ms for that token, and 210 ms for a nested calc(175ms * 1.2) scope. They read one easing for a calc() argument, in Chromium and WebKit. With no stylesheet, --duration-exit reads 175 ms, or the element's --duration-fast.
  • Product/runtime behavior verified unchanged: SegmentedControl's lens. The no-token path is themeTimingOf, moved as is. Its interaction spec, with the new calc() case, passes on main's build and this one. The curve matches main's timedCurve at all 293,040 samples before its end (not-for-landing 3534c2d9cc). Past its end the velocity is 0 instead of a one-sided slope or NaN, which a held segment's velocity read can see.

Scope

  • No intended public API, product behavior, visual direction, or policy change.
  • Product changes discovered during the work were removed or split.
  • Public text and artifacts contain no internal Meta context.

Testing

At this head on main 57e0540. The unit, type and lint runs were at c7ecbc6, whose code is the same; one comment differs.

  • pnpm exec vitest run --project ui packages/core/src/motion packages/core/src/SegmentedControl packages/core/src/utils packages/core/src/internal packages/lab/src/RefreshControl: 2,123 passed in 95 files.
  • pnpm -F @astryxdesign/core typecheck: 0 errors. CI=true pnpm lint: 0 errors and no new warning. check:knowledge, check:changesets, review:pre (0 findings, 847 lines) and the public-text check pass.
  • themeTiming.interaction.browser.spec.ts: Chromium 6/6, WebKit 6/6. On not-for-landing 5fbdda3b66, which reads token text with a default fallback and no probe, 5 of the 6 fail. The no-stylesheet default case passes there.
  • SegmentedControl.interaction.browser.spec.ts, this branch's file, ran against a Storybook built from main and one from this branch, order-balanced. Chromium: 47 passed in each of four runs. WebKit: 44 passed and 3 skipped by design on both. SegmentedControl's code is unchanged since.
  • Not-for-landing 3534c2d9cc compares main's timedCurve with the new curve over 293,040 samples: 5 easings with over- and undershoot, 8 lengths and 6 ranges. at is identical, and the velocity is within 1.5e-7 before the end.

@vercel

vercel Bot commented Nov 5, 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 5, 2026 2:14pm UTC

Request Review

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

astracat-bot Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 5, 2026, 2:19 PM UTC

@cixzhang

cixzhang commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

/approve-spec 4300371

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · dbb2ff3

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
DateTimeInput 186.1 kB (+565 B) · 17.2 kB CSS (0) — — · — · —
SegmentedControl 84.4 kB (+484 B) · 6.7 kB CSS (0) — ✓ · ✓ · ✓
SegmentedControlItem 12.1 kB (0) · 4.0 kB CSS (0) — ✓ · ✓ · ✓

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

API changes: none in this pull request

Committed API report behind this build: cli 9 rows, core 4 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

@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.

Changes requested. The shared reader and SegmentedControl's move onto it look right: the slide curve is unchanged, and calc() tokens resolve as the transition resolves them. Two things need fixing first:

  • pressFadeMs (packages/core/src/utils/pressFeedback.ts:165-178) and Lab's endTiming (packages/lab/src/RefreshControl/refreshPull.ts:175-188) still parse token text beside the new reader, so with --duration-exit: calc(0.1s * 2) a press's fading state clears at 175 ms while its fade plays 200 ms, and with a calc() --duration-medium RefreshControl's end skips its slide; please route both through readThemeTiming (exported by name from @astryxdesign/core/internal/touch for Lab), or say in the description why it cannot serve them.
  • readThemeTiming(element, {duration: '--duration-exit', …}) returns no curve where no stylesheet sets the token, because its declared default var(--duration-fast) is resolved on a probe under <body> where nothing defines --duration-fast (themeTiming.ts:105); resolve a var() default against the element before writing it, and add a --duration-exit case to themeTiming.test.ts.

[Automated review]

Comment thread packages/core/src/motion/themeTiming.ts Outdated
probe.style.setProperty('display', 'none', 'important');
probe.style.setProperty(
'transition-duration',
read(tokens.duration, durationDefaults[tokens.duration]),

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.

--duration-exit's declared default is var(--duration-fast). On this probe under <body>, nothing defines --duration-fast when no stylesheet sets the tokens, so the probe's duration computes to 0s. The reader then returns no curve instead of core's 175 ms. Resolve a var() default against the element before you write it here, and add a --duration-exit case to themeTiming.test.ts.

@@ -2367,6 +2312,87 @@ test('a drag commits through the destination item’s click too: its onClick run
});

/** A desktop context: a mouse, no touch, a fine primary pointer. */

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: this JSDoc describes openWithMouse. It now sits above clickSlide's own JSDoc, so openWithMouse lost its description. Move it back above openWithMouse.

Core gains motion/themeTiming.ts. resolveTiming resolves a duration and
an easing written in CSS as a transition resolves them, so the browser
computes calc(). readThemeTokens reads theme tokens where an element
is; a token with no value reads the default core declares, and the
references in that default read their tokens there too. readThemeTiming
builds the eased progress from those tokens or from the element's own
transition. It returns no curve when the duration is not a positive
length or the easing does not parse.

SegmentedControl's selection slide drops its private themeTimingOf and
timedCurve for these. It reads the same transition and plays the same
curve, so its timing is unchanged, calc() tokens included.
@vjeux

vjeux commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

On the first point: routing pressFadeMs and Lab's endTiming through the reader changes their timing for hand-written calc() tokens. Under Reviews contract scope; they do not expand it, that ships as its own pull request, #10069, which depends on this one. The var() default and the JSDoc are fixed at 3785e40.

@cixzhang

cixzhang commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

/approve-spec 3785e40

@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.

Approved pending CI: CI has not run on this head yet. The pull request is a draft from a fork: once it is marked ready, a maintainer adds the ci:run label so CI runs.

There are no blocking findings: the shared reader resolves calc() tokens, nested scopes and the declared defaults as a transition does, SegmentedControl's slide curve is unchanged, and the --duration-exit default and the openWithMouse JSDoc are fixed. Moving pressFadeMs and Lab's endTiming onto the reader in #10069 is fine as its own change.

Non-blocking suggestions:

  • packages/core/src/motion/themeTiming.ts:69 and :77: the JSDocs on firstDurationMs and firstEasing restate their names and parameter type; consider deleting them.
  • packages/core/src/motion/themeTiming.ts:96-97: "The easing is null when it is not a cubic Bézier, and a text left out gives null." carries two topics; consider "The easing is null when it is not a cubic Bézier. A value left out gives null."

[Automated review]

};
}

/** The first transition's duration in a computed style, in 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.

Non-blocking: this JSDoc and the one on firstEasing (line 77) restate the function names and their parameter type. Consider deleting both.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in #10069 (f548111); #10068 stays as approved.

* them where `element` is. A plain time or easing parses as written. Other
* text, such as `calc()`, resolves on a hidden probe's transition. The
* duration is null when it is not a time of zero or more. The easing is null
* when it is not a cubic Bézier, and a text left out gives 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.

Non-blocking: this sentence carries two topics. Consider: "The easing is null when it is not a cubic Bézier. A value left out gives null."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in #10069 (f548111); #10068 stays as approved.

@vjeux
vjeux marked this pull request as ready for review November 5, 2026 11:35
@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 5, 2026
@cixzhang
cixzhang marked this pull request as draft November 5, 2026 11:39
@cixzhang
cixzhang marked this pull request as ready for review November 5, 2026 11:39

@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.

Approved pending CI: CI is still running on this head.

There are no blocking findings. The shared reader resolves calc() tokens, nested scopes and the declared defaults as a transition does, SegmentedControl's slide keeps its timing, and the merge of main leaves this pull request's own changes as they were.

Non-blocking suggestion:

  • packages/core/src/motion/themeTiming.ts:11-12: since spec:AST-094 FR45 changed on main, a gesture component's tap-started move under touch plays a spring, so "Motion that a tap, a key or the program starts reads its duration and easing from the theme with it." overstates where the reader applies; consider "Motion that plays the theme's curve tokens reads its duration and easing with it."

[Automated review]

Comment on lines +11 to +12
* @position Motion foundation, internal to core. Motion that a tap, a key or
* the program starts reads its duration and easing from the theme with it.

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: since spec:AST-094 FR45 changed on main, a gesture component's tap-started move under touch plays a spring (SegmentedControl's own settleLens springs when presenting). Consider: "Motion that plays the theme's curve tokens reads its duration and easing with it."

@cixzhang
cixzhang merged commit 1dce318 into meta:main Nov 5, 2026
66 checks passed
@vjeux
vjeux deleted the uikit/c21-theme-timing branch November 5, 2026 15:14

This branch was successfully deployed

1 active deployment
Preview — dbb2ff30 Deployed Nov 5, 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