Skip to content

refactor(Selector): the presentation controller holds its choice through the layer runtime's presentation hold - #8591

Merged
cixzhang merged 1192 commits into
mainfrom
feat/presentation-hold-selector
Nov 10, 2026
Merged

cixzhang merged 1192 commits into
mainfrom
feat/presentation-hold-selector

Conversation

@cixzhang

@cixzhang cixzhang commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #8587 (the layer runtime's presentation hold). The base is its branch, so this diff is only the Selector adoption.

What it does

useSelectorPresentation, the presentation controller Selector and MultiSelector share, kept two latches of its own:

  • activePresentationRef: the presentation an opening chose (sheet or popover). It's now a createPresentationHold, taken at show().
  • isSheetPresented: the sheet kept mounted after it closes, until BottomSheet's final-focus handoff reaches the trigger. It's now a usePresentationHold over the sheet's open state.

Both are released exactly where the old state was cleared: when the trigger takes focus after the sheet's exit, and, for the sheet hold, when a popover opens instead. architecture:layer-runtime INV14 names this job, keeping a layer's chosen presentation from the open until its close settles, as the runtime's.

No behavior change

Selector's and MultiSelector's tests are the oracle and pass unchanged (486), including the sheet presentation's exit and its focus return to the trigger. The real-browser check is their specs, which this PR's CI runs because the change touches the Selector folder.

Size (gzip KB, minified)

The same method as #8587: a fresh packages/core dist at the base and at this head; esbuild bundle, minify, splitting, ESM, packages external.

Component Desktop Phone
Selector 65.73 → 65.90 (+0.17) 82.58 → 82.75 (+0.17)
MultiSelector 62.34 → 62.51 (+0.17) 75.56 → 75.73 (+0.17)

Testing

  • pnpm vitest run --project ui packages/core/src/Selector packages/core/src/MultiSelector: 486 pass.
  • tsc and eslint clean.
  • [chore] changeset.

vjeux and others added 30 commits October 26, 2026 01:43
#8176's head merges #8076's 4adaf8b (main 61480b5 with #8257). No
conflicts; `timing.ts` is #8176's, with #8484's keyboard export.
The host read getComputedStyle(element).touchAction at a recognizer's
first attach, to keep a caller's own touch-action in force; inside a
mount that forces a style recalc over everything just mounted (C21's
200-row year wheel: 9.2 ms at 1x, rows written afterward recalc again).
Failing on this head: attaching calls getComputedStyle, and a caller's
stylesheet value is intersected at once. A caller's inline value applies
at once with no read; a stylesheet's is checked after the frame has
painted.
A caller's inline touch-action is the style's own, read with no recalc, and
applies at once. A stylesheet's needs a computed read, which now waits
until the next frame has painted, when styles are clean, instead of
running inside the attach, where it forced a style recalc over whatever
had just mounted. The check is batched: the host's own values come off
every pending element, one read serves them all, and the writes follow.
Until it runs (a frame or two after the element mounts) the host's own
value stands, so a caller's narrower stylesheet value can read wider for
that long; no touch starts on an element in the frame it mounts in.
…on clock and Reduce Motion plan

The motion README takes main's internal-roles sentence with this layer's
animator; uikit.test.ts takes main's version (rows, docAbove) and keeps the
check of values bound from an exported group, which timing.ts's Reduce
Motion fade bindings need.
architecture:react-component-runtime INV3 asks every Effect to name the
external system it synchronizes: the listener ref, the recognizer's
target-action listener and isEnabled, the host attachment, the tracker's
options, tracking expansion, press consumer and enabled state, the unmount
flag, and the attachment's node.
… proof describe the roles' table values (DEC-11)
…reader

architecture:react-component-runtime INV11 allows the keyboard module at
most one layout read per keyboard change. `getMobileKeyboardHeight`
measured again on every call, and the layout guide, each component's
`useKeyboardHeight` and ChatLayout's commit all call it after the module
has already measured the report: one show read the visual viewport's
height 6 times in Full AI Chat in Chromium, 13 times in the module's test
with the guide, a listener and two hooks.

While the module listens, `getMobileKeyboardHeight` returns the height it
measured at the last report. Every change of the visual viewport or the
window is a report, so a reader between two reports still sees the current
height; with nothing listening yet, it measures.

Tests: the module's test counts one read for a report with the guide, a
listener and two hooks reading the height (red before: 13), and an
interaction test counts one read for a show in Full AI Chat (red on the
previous build: 6).
…is focused without the reveal

spec:AST-099 FR4 says every route into the composer's text, a tap
included, focuses it without scrolling the page. The tap route claimed only
contenteditable text: a `<textarea>` or `<input>` passed as ChatComposer's
input (its documented plain textarea) was left to the browser, and with
nothing focused no blur reaches the focus takeover, so Safari revealed the
field by scrolling the document.

The tap route now claims an unfocused text control in the composer that
brings up a keyboard, and delivers it as it delivers contenteditable text:
focused with `preventScroll`, with the caret where the standard
`caretPositionFromPoint` maps the point inside the control, or after its
text where the browser maps none. A focused control keeps its own taps (the
browser moves the caret); a checkbox or an `inputmode="none"` field is never
claimed.

Tests (useChatKeyboard.test.tsx): ChatLayout with a textarea composer,
under a coarse pointer, cancels the tap's default and focuses the textarea
with `preventScroll` (red before: the browser's own focus); the claim takes
an unfocused text control and leaves a focused one, a checkbox and an
`inputmode="none"` field; the caret lands at the mapped offset, or after
the text.
…d Chrome it moves once reported

spec:AST-099 FR8 asks a ride within one frame of the keyboard on the
measured keyboards, with Android emulator evidence against Gboard; Firefox
for Android has FR2–FR5 only, and reports the keyboard once it is up. This
branch plays UIKit's keyboard spring from the browser's report there, and
times no ride to Gboard. The docs said the composer rides in step in
Firefox for Android and rides the keyboard in Chrome on Android.

ChatLayout's docs (English, Chinese, dense), the browser-support guide and
the changeset now say: in Safari on iOS the composer rides on top of the
keyboard in step with it; in Firefox for Android and Chrome on Android it
moves above the keyboard once the browser reports it; under Chrome's
`interactive-widget=resizes-content` it stays above it without moving.
…es a dip lands its move with it

Under Reduce Motion on a touch screen:
- A move over a stylesheet opacity of 0 dips nothing (it lands at once), but
  kept 0 as a borrow that outlived it, so a later move once the element
  showed read it as invisible and landed in view. A borrow now exists only
  while its dip runs.
- stop() on a dip's opacity finished the fade but left the move's pending
  jump to land later, at opacity 1. A finished fade now lands the travel
  waiting for it at the same instant.
…ll request

This pull request keeps curve sampling (hold, seek, sample, release, the
curve end); the recorder, waitForAnimation, watchAnimations and waitForRest,
with their self-tests, land separately on top. The holding self-tests that
waited with them now poll the page for a running or idle animation. Chromium:
19 tests, 5x repeat, pass.
The harness's animation-state instruments, split out of the curve-sampling
pull request so each stays reviewable:

- a page-side recorder that sees every animation from its first frame or
  creation, so one that starts and ends before a test looks is still
  reported, with its finish time and start (kept when the page cancels it);
- waitForAnimation: the running animations on an element past a minimum
  progress, or the ones that finished since the last wait, with their curve
  interval through the playback rate (a run going backward is dated from
  when it began);
- watchAnimations: a watch taken before an action, for an entrance on a
  page's first contact;
- waitForRest: rest judged by presented transform, translate, rotate, scale
  and opacity, not playState, so an end value held by the keyframes is not
  waited out, and a backward run's end delay and curve are.

Self-tests cover each in real Chromium.

Co-authored-by: Christopher Chedeau <[email protected]>
# Conflicts:
#	packages/core/src/motion/README.md
#	packages/core/src/motion/uikit/uikit.test.ts
…inishes a dip lands its move); a pseudo-element's own opacity hold is owned

Conflicts in animator.ts take this layer's Reduce Motion plan, which gains
#8055's rule in its own terms: a stylesheet that hides the element lends
nothing, so the move lands at once with no dip and no borrow. #8055's stop
rule already holds under the plan (the opacity pass lands the waiting move);
its test passes unchanged. uikit.test.ts takes #8055's ordering.

Also fixed (CodeBunny on 3d201a0): a pseudo-element shown with
set({opacity: 1}) over a stylesheet that hides it holds that value with an
animation, which now counts as an owned opacity (writesOwnOpacity), so a
move or a fade by role returns to it instead of borrowing the hiding 0.
# Conflicts:
#	packages/core/src/BottomSheet/BottomSheetPanel.tsx
… Effects; #8072 61e891d) into #8076

Both of cixzhang's rules kept: #8073's useNodeAttachment (a replaced node
re-attaches, deps re-attach, each Effect names what it syncs) and #8076's
guards, so neither the isEnabled sync's cancel nor a press tracker's
release calls a caller back from an Effect. Both sides' tests stay.
… from its trigger

A semantic merge:
- Popover.tsx: the grow-from-trigger motion (usePopoverSurfaceMotion) sits
  beside main's bottom-sheet presentation (usePresentationSurface and the
  controlled-surface latch). It runs only when the anchored layer shows; a
  render-prop trigger records its anchor through setRenderTrigger.
- motion/uikit/springs.ts takes main's per-spring constants and adds
  POPOVER_PRESENT_SPRING and POPOVER_DISMISS_SPRING with their rows;
  index.ts and the motion README list both keyboard and popover.
- layer-runtime.md takes main's INV14/INV15 status paragraph.
Her af953bd merges #8076's bd9246d (main 2af4d30, with #8229's
Popover presentation) into this branch, with her resolution of
BottomSheetPanel.tsx against #8229. No conflicts with this branch's
commits since 2d520a6: the result is her head plus those commits (the
keyboard-height Effect's INV3 comment, one layout read per keyboard
change, the text control tap route, and the Safari/Firefox/Chrome docs).

`timing.ts` checked: #8076's with exactly #8484's change.
# Conflicts:
#	packages/core/src/gestures/GestureHost.ts
#8176's local head reads the layout once per keyboard change, focuses a
text control composer tapped with nothing focused without the reveal, says
the composer moves above the keyboard once reported in Firefox and Chrome
for Android, and merges the maintainer's af953bd (#8076's bd9246d,
main 2af4d30 with #8229). No conflicts; `timing.ts` is #8176's.
…longer has delegated consumers

#8076 carries the host without delegated consumers, which nothing used,
so #8309's FR41 case for a delegated pressable has no subject left. The
press-tracked and attached cases still cover native selection on a hold
that does nothing (spec:AST-094 FR41).
…ides in step

#8176 says the composer moves above the keyboard once Chrome reports it,
since it times no ride to Gboard (spec:AST-099 FR8 asks a ride within one
frame of the keyboard, with Android emulator evidence). This branch times
the ride to Gboard's measured slides, with that evidence: ChatLayout's docs
(English, Chinese, dense) and the browser-support guide say the composer
rides Gboard's slides in step in Chrome on Android, while a Tall
BottomSheet makes its room once Chrome reports the keyboard. Firefox for
Android keeps #8176's wording: it moves once Firefox reports the keyboard.
cixzhang and others added 6 commits October 26, 2026 12:03
…nimator fixes) into uikit/c26-popover-present
…ation until its close settles

architecture:layer-runtime INV14 gives the layer runtime the presentation
hold: keeping a layer's chosen presentation from the open until the close
settles. Layer/presentationHold.ts (internal) is that one job:
createPresentationHold for code that chooses at an open event, and
usePresentationHold for a choice taken during render; the component releases
it when its close settles.

Popover adopts it for its three latches, with no behavior change: the
controlled surface (taken as isOpen turns on, let go as it turns off), the
sheet kept mounted until its dialog has closed, and the touch-or-pointer
presentation its close plays in (usePopoverSurfaceMotion). Not the input
hold (inputHold.ts). Not exported; a test locks that.

Co-authored-by: Christopher Chedeau <[email protected]>
…the record names the shared hold

usePopoverSurfaceMotion's returned callback reads touchHold, so it is in its
dependency list (lint). architecture:layer-runtime's current-gaps paragraph
no longer says no shared presentation hold exists or that Popover builds
its own: the runtime owns it (Layer/presentationHold.ts) and Popover uses
it; Owning code and verified_by name it.
…ugh the layer runtime's presentation hold

useSelectorPresentation (Selector and MultiSelector) kept two latches of its
own: activePresentationRef, the presentation an opening chose, and
isSheetPresented, the sheet kept mounted after it closes until BottomSheet's
focus handoff reaches the trigger. Both now use the layer runtime's
presentation hold (Layer/presentationHold): createPresentationHold taken at
show, and usePresentationHold over the sheet's open state, released where
the old state was cleared. No behavior change; Selector and MultiSelector
tests pass unchanged.
@vercel

vercel Bot commented Oct 26, 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 9, 2026 5:05pm UTC

Request Review

@astracat-bot

astracat-bot Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 9, 2026, 7:25 PM UTC

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · a5a3b5b

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
Selector 100.1 kB (+165 B) · 17.4 kB CSS (0) — ✗ · ✓ · ✓
SelectorOption 20.9 kB (0) · 6.1 kB CSS (0) — ✗ · ✓ · ✓
PowerSearch 287.5 kB (+188 B) · 24.1 kB CSS (0) — — · — · —
3 more components
Component Size LoC Visual · A11y · RTL
MultiSelector 95.1 kB (+166 B) · 16.8 kB CSS (0) — — · — · —
Pagination 110.1 kB (+148 B) · 17.8 kB CSS (0) — — · — · —
richtext/RichTextEditorToolbar 278.4 kB (+136 B) · 454 B CSS (0) — — · — · —
Visual changes: 4 snapshots in 1 component

A change is a question for the reviewer, not a failure.

Component · story Before After Diff
Selector · Indicator Space Bottom Sheet Wide Start (neutral, dark) before frame after frame diff frame
Selector · Indicator Space Bottom Sheet Wide Start (neutral, light) before frame after frame diff frame
Selector · Indicator Space Bottom Sheet Narrow End RTL (neutral, dark) before frame after frame diff frame
Selector · Indicator Space Bottom Sheet Narrow End RTL (neutral, light) before frame after frame diff frame

Package size: @astryxdesign/core 7.22 MB packed (+356 B); no new dependencies.

API changes: none in this pull request

Committed API report behind this build: cli 29 rows, core 36 rows, theme-butter 1 row, theme-y2k 1 row; 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.

Recommending approval. useSelectorPresentation now keeps the opening's presentation and the closing bottom sheet through the layer runtime's presentation hold, as architecture:layer-runtime INV14 asks, and Selector and MultiSelector behave as they do on the base branch: the unit suites pass, a presentation-flip check matches state for state, and Chromium captures of both surfaces are pixel-identical. Two small follow-ups:

  • The layer-runtime record's current-gaps paragraph on the base branch names only Popover as using the shared presentation hold and still lists Selector among components that build their own; please amend it in whichever of #8587 and this PR lands last.
  • CI runs only for pull requests into main and release branches, so the Selector specs the description mentions have not run on this branch yet.

[Automated review]

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 27, 2026
@cixzhang
cixzhang force-pushed the feat/presentation-hold branch from 99b0ba8 to cf409fc Compare November 7, 2026 15:54
@github-actions
github-actions Bot deleted the branch feat/presentation-hold November 8, 2026 06:04
The presentation hold (#8587) merged into main, so this branch now targets
main. The Selector adoption's own diff is unchanged.
@cixzhang
cixzhang changed the base branch from feat/presentation-hold to main November 9, 2026 15:33
@cixzhang cixzhang added ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) labels Nov 9, 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.

Recommending approval. useSelectorPresentation now keeps the opening's presentation and the closing bottom sheet through the layer runtime's presentation hold, as architecture:layer-runtime INV14 asks, and Selector and MultiSelector behave as on main: their unit suites pass on both, and Chromium captures of both bottom sheets and both popovers are pixel-identical. Approved pending CI: this push deferred the heavy suites, including the Selector browser specs, to the pre-merge run.

Non-blocking:

  • The Current gaps paragraph in docs/architecture/layer-runtime.md (lines 663-669) still names only Popover as using the shared hold and lists Selector among components that build their own; please update it here or right after.
  • Two changed comments in useSelectorPresentation.ts (lines 79-84 and 181-184) still run past INV29's 25-word sentence limit; the earlier inline suggestions apply.
  • The size table could add the gzip CSS delta INV6 asks for (zero here, since no style source changes).

[Automated review]

Comment on lines +79 to +84
// The layer runtime's presentation holds (Layer/presentationHold): the
// presentation an opening chose, taken as it shows; and the sheet, held from
// the render that opens it until its close settles. BottomSheet owns its
// exit animation and final-focus handoff, so the sheet stays mounted after
// the controlled open state turns false until that handoff reaches the
// trigger; then consumers may remove the hidden surface tree.

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 (INV29): these two sentences run 29 and 34 words, cover both holds at once, and the first restates the code below. A rewrite that keeps only the constraint:

// The sheet stays mounted after it closes. BottomSheet plays its exit, then
// moves focus to the trigger. Only then can consumers remove the sheet.

Comment on lines 181 to +184
// BottomSheet focuses finalFocusRef only after its exit completes. That
// focus event is the lifecycle signal that the retained sheet can now
// leave the tree without dropping focus to the document body.
setIsSheetPresented(false);
// leave the tree without dropping focus to the document body: its
// close has settled.

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 (INV29): the appended clause makes the second sentence 27 words; a description sentence stays within 25.

// BottomSheet focuses the trigger only after its exit ends. This focus
// means the close has settled, so the sheet can leave the tree.

@cixzhang
cixzhang merged commit 630ae5e into main Nov 10, 2026
111 of 114 checks passed
@github-actions
github-actions Bot deleted the feat/presentation-hold-selector branch November 10, 2026 06:04

This branch was successfully deployed

1 active deployment
Preview — a5a3b5b0 Deployed Nov 9, 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) ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) 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