Repository navigation
perf(core): hit areas read no layout during a scroll or a press at rest - #11083
Conversation
A touch hit area read the rect of every interactive element on the page in a finger's pointerdown, before the browser could start the touch's scroll. Its passes also ran in the frames of a scroll, and under an ancestor's motion, as when a screen slides in. The press now arms a check that its click runs. The click comes only once the touch is a tap. It reads the control's box without its own press scale and writes no insets: a pass after the press's motion ends takes them. No pass runs while the page scrolls, until scrollend or 150 ms without a scroll event. A pass skips a control while an ancestor runs a finite animation, and measures it once the animation ends. The page's interactive elements are kept across mutations and watch changes, so a layer that opens or closes is matched alone, not the whole page.
|
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 |
|---|---|---|
| richtext/RichTextEditorToolbar | 281.3 kB (+1.2 kB) · 454 B CSS (0) | — |
| lab/Comments | 355.5 kB (+1.1 kB) · 2.5 kB CSS (0) | — |
| lab/TransferListSelector | 112.2 kB (+1.1 kB) · 1.4 kB CSS (0) | — |
94 more components
| Component | Size | LoC |
|---|---|---|
| lab/EmojiPicker | 89.2 kB (+1.1 kB) · 751 B CSS (0) | — |
| lab/DialogHeroHeader | 85.4 kB (+1.1 kB) · 372 B CSS (0) | — |
| richtext/RichTextView | 278.8 kB (+1.1 kB) · 2.3 kB CSS (0) | — |
| Stepper | 64.0 kB (+1.1 kB) · 10.1 kB CSS (0) | — |
| Pagination | 112.7 kB (+1.1 kB) · 17.8 kB CSS (0) | — |
| Typeahead | 83.0 kB (+1.1 kB) · 12.4 kB CSS (0) | — |
| ChatLayoutScrollButton | 62.9 kB (+1.1 kB) · 10.2 kB CSS (0) | — |
| Field | 57.1 kB (+1.1 kB) · 7.2 kB CSS (0) | — |
| ChatLayout | 85.0 kB (+1.1 kB) · 10.5 kB CSS (0) | — |
| AppShell | 93.9 kB (+1.1 kB) · 13.5 kB CSS (0) | — |
| Slider | 111.3 kB (+1.1 kB) · 8.8 kB CSS (0) | — |
| InputGroup | 58.7 kB (+1.1 kB) · 7.8 kB CSS (0) | — |
| DateInput | 189.7 kB (+1.1 kB) · 17.0 kB CSS (0) | — |
| Switch | 105.9 kB (+1.1 kB) · 9.9 kB CSS (0) | — |
| lab/SelectableCardGroup | 66.5 kB (+1.1 kB) · 162 B CSS (0) | — |
| ChatComposer | 80.6 kB (+1.1 kB) · 12.0 kB CSS (0) | — |
| ButtonGroup | 43.0 kB (+1.1 kB) · 3.7 kB CSS (0) | — |
| MobileNavToggle | 62.6 kB (+1.1 kB) · 10.0 kB CSS (0) | — |
| lab/ChatReactionBar | 109.6 kB (+1.1 kB) · 1.1 kB CSS (0) | — |
| SideNavHeading | 77.8 kB (+1.1 kB) · 11.3 kB CSS (0) | — |
| DrawerHeader | 65.3 kB (+1.1 kB) · 12.9 kB CSS (0) | — |
| RadioListItem | 69.5 kB (+1.1 kB) · 10.1 kB CSS (0) | — |
| TextArea | 64.5 kB (+1.1 kB) · 9.3 kB CSS (0) | — |
| Lightbox | 124.8 kB (+1.1 kB) · 10.6 kB CSS (0) | — |
| Thumbnail | 66.7 kB (+1.1 kB) · 11.6 kB CSS (0) | — |
| Banner | 64.3 kB (+1.1 kB) · 10.5 kB CSS (0) | — |
| ComplexSelector | 73.2 kB (+1.1 kB) · 11.8 kB CSS (0) | — |
| SideNavCollapseButton | 63.2 kB (+1.1 kB) · 10.0 kB CSS (0) | — |
| TextInput | 69.9 kB (+1.1 kB) · 11.2 kB CSS (0) | — |
| ToggleButton | 88.8 kB (+1.1 kB) · 10.1 kB CSS (0) | — |
| ChatSendButton | 62.7 kB (+1.1 kB) · 10.0 kB CSS (0) | — |
| RadioList | 58.4 kB (+1.1 kB) · 7.3 kB CSS (0) | — |
| InfoTip | 48.6 kB (+1.1 kB) · 5.4 kB CSS (0) | — |
| lab/DiffViewer | 89.5 kB (+1.1 kB) · 2.1 kB CSS (0) | — |
| lab/ListInput | 90.4 kB (+1.1 kB) · 922 B CSS (0) | — |
| FieldLabel | 53.1 kB (+1.1 kB) · 5.7 kB CSS (0) | — |
| AlertDialog | 107.8 kB (+1.1 kB) · 14.6 kB CSS (0) | — |
| CodeBlock | 77.4 kB (+1.1 kB) · 11.3 kB CSS (0) | — |
| DateRangeInput | 95.3 kB (+1.1 kB) · 12.5 kB CSS (0) | — |
| lab/TransferList | 104.5 kB (+1.0 kB) · 1.2 kB CSS (0) | — |
| Toast | 100.2 kB (+1.0 kB) · 10.3 kB CSS (0) | — |
| NumberInput | 73.8 kB (+1.0 kB) · 11.4 kB CSS (0) | — |
| BaseTypeahead | 74.0 kB (+1.0 kB) · 10.9 kB CSS (0) | — |
| DateTimeInput | 211.3 kB (+1.0 kB) · 18.7 kB CSS (0) | — |
| TableSelectionToolbar | 72.6 kB (+1.0 kB) · 13.2 kB CSS (0) | — |
| CheckboxListItem | 73.4 kB (+1.0 kB) · 11.4 kB CSS (0) | — |
| TopNavHeading | 77.4 kB (+1.0 kB) · 11.2 kB CSS (0) | — |
| IconButton | 62.4 kB (+1.0 kB) · 10.0 kB CSS (0) | — |
| ChatDictationButton | 62.9 kB (+1.0 kB) · 10.1 kB CSS (0) | — |
| BreadcrumbItem | 86.9 kB (+1.0 kB) · 12.1 kB CSS (0) | — |
| lab/TourStep | 99.5 kB (+1.0 kB) · 590 B CSS (0) | — |
| DialogHeader | 65.1 kB (+1.0 kB) · 11.5 kB CSS (0) | — |
| ListItem | 72.4 kB (+1.0 kB) · 11.4 kB CSS (0) | — |
| SegmentedControlItem | 18.5 kB (+1.0 kB) · 4.3 kB CSS (0) | — |
| MultiSelector | 97.3 kB (+1.0 kB) · 16.8 kB CSS (0) | — |
| TableCell | 112.5 kB (+1.0 kB) · 17.9 kB CSS (0) | — |
| TabMenu | 74.1 kB (+1.0 kB) · 11.1 kB CSS (0) | — |
| lab/Schedule | 108.3 kB (+1.0 kB) · 3.9 kB CSS (0) | — |
| PowerSearch | 292.9 kB (+1.0 kB) · 24.2 kB CSS (0) | — |
| TopNavMenu | 76.9 kB (+1.0 kB) · 11.2 kB CSS (0) | — |
| lab/ChatEmojiPicker | 108.5 kB (+1.0 kB) · 773 B CSS (0) | — |
| lab/CommentThread | 348.5 kB (+1.0 kB) · 2.4 kB CSS (0) | — |
| Button | 62.3 kB (+1.0 kB) · 10.0 kB CSS (0) | — |
| Carousel | 72.1 kB (+1.0 kB) · 10.9 kB CSS (0) | — |
| MoreMenu | 99.7 kB (+1.0 kB) · 17.6 kB CSS (0) | — |
| TableHeaderCell | 112.1 kB (+1.0 kB) · 17.6 kB CSS (0) | — |
| lab/CommentComposer | 154.7 kB (+1.0 kB) · 1.9 kB CSS (0) | — |
| ChatComposerInput | 78.3 kB (+1.0 kB) · 11.3 kB CSS (0) | — |
| ChatComposerTokenElement | 78.3 kB (+1.0 kB) · 11.3 kB CSS (0) | — |
| DropdownMenu | 99.4 kB (+1.0 kB) · 17.6 kB CSS (0) | — |
| FileInput | 71.3 kB (+1.0 kB) · 10.9 kB CSS (0) | — |
| Popover | 93.2 kB (+1.0 kB) · 14.2 kB CSS (0) | — |
| lab/PageControl | 76.6 kB (+1.0 kB) · 709 B CSS (0) | — |
| Calendar | 73.3 kB (+1.0 kB) · 10.6 kB CSS (0) | — |
| Tokenizer | 94.7 kB (+1.0 kB) · 18.8 kB CSS (0) | — |
| MobileNav | 72.7 kB (+1.0 kB) · 10.6 kB CSS (0) | — |
| lab/TabBarMoreList | 94.6 kB (+1.0 kB) · 1.8 kB CSS (0) | — |
| Selector | 102.6 kB (+1.0 kB) · 17.4 kB CSS (0) | — |
| TimeInput | 164.8 kB (+1.0 kB) · 16.0 kB CSS (0) | — |
| CheckboxInput | 66.4 kB (+1.0 kB) · 9.2 kB CSS (0) | — |
| SideNav | 116.9 kB (+1.0 kB) · 11.4 kB CSS (0) | — |
| CheckboxList | 70.7 kB (+1.0 kB) · 7.7 kB CSS (0) | — |
| TopNavMegaMenu | 71.9 kB (+1.0 kB) · 11.8 kB CSS (0) | — |
| richtext/RichTextEditor | 300.6 kB (+1.0 kB) · 2.6 kB CSS (0) | — |
| SideNavItem | 72.6 kB (+1.0 kB) · 11.1 kB CSS (0) | — |
| ContextMenu | 111.2 kB (+1017 B) · 17.4 kB CSS (0) | — |
| Markdown | 191.0 kB (+1014 B) · 20.7 kB CSS (0) | — |
| Table | 128.1 kB (+1006 B) · 18.4 kB CSS (0) | — |
| ToggleButtonGroup | 40.3 kB (+1000 B) · 3.7 kB CSS (0) | — |
| TopNav | 74.4 kB (+995 B) · 10.9 kB CSS (0) | — |
| SegmentedControl | 97.3 kB (+49 B) · 6.9 kB CSS (0) | — |
| lab/TabBar | 81.3 kB (+48 B) · 1.8 kB CSS (0) | — |
| Timestamp | 34.6 kB (+3 B) · 10.2 kB CSS (0) | — |
| lab/TabBarItem | 3.9 kB (0) · 1.8 kB CSS (0) | — |
Package size: @astryxdesign/core 7.29 MB packed (+6.7 kB); no new dependencies.
Not run on this PR: add ci:run-visual or ci:run-rtl to run them.
Generated by PR Enrichment workflow | View full report
There was a problem hiding this comment.
Changes requested. The click-time press check, the scroll gate and the ancestor-animation hold behave as described, and their new unit cases fail on main and pass here. Two things need fixing first:
regroup(packages/core/src/utils/hitArea.ts:642-646) checks every kept interactive element on each new watch, so watching 300 rows beside 2,000 buttons now takes about 26–30 ms in Chromium against about 1 ms onmain; deleting onlyelement.querySelectorAll(INTERACTIVE_SELECTOR)beforeaddMatchesbrings it to about 2 ms, and every existing hit-area test still passes.- The new
settlingAnimationsandscheduleAtRest(hitArea.ts:724-735,972-996) copy the at-rest gate inpackages/core/src/utils/touchHitArea.ts:68-80with different rules, so please keep one shared helper inhitArea.tsand haveuseTouchHitAreause it instead of its own copy.
Optional: the scroll-stop detector repeats the one in Layer/useLayer.tsx, and the interactive JSDoc says each mutation updates the set, although a removal leaves only at the next read.
[Automated review]
A new watch checked every interactive element the page kept, so a layer of watched rows cost the rows times the page's controls. It now regroups only the interactive elements it holds. The pass, the click's follow-up pass and useTouchHitArea wait out motion through one helper: the finite animations running or held in a scope, until each settles. useTouchHitArea had its own copy, and the click's follow-up counted only running animations.
There was a problem hiding this comment.
Approved pending CI: CI has not run on this head yet, because the pull request is a draft from a fork. Once it is ready for review, a maintainer adds the ci:run label so CI runs.
Both earlier requests are addressed: a new watch now regroups only its own subtree (packages/core/src/utils/hitArea.ts:643-646), and the pass, the click's follow-up and useTouchHitArea share one at-rest helper pair. Optional: the scrollend-or-150 ms detector still repeats the ones in Layer/useLayer.tsx and gestures/fingerScroll.ts.
[Automated review]
Whether the page is scrolling is page state, so every copy of Core shares one scroll gate under a registered key. The first copy to observe listens for the page, and the last one to stop ends it. Each watch keeps the ancestor animations it waits out, so no module map holds another copy's watches.
A pass that sees an ancestor animation move a control holds it back, and the press then measures it, while its box is still where the finger landed. A control at rest still reads nothing at the press, and its click measures. An animation that starts after the press moves the boxes before the click, so the control's click goes through, as the browser's hit test took it, and a moving neighbour is left out. A fade or a tint moves nothing, so the click's check still runs.
|
/approve-spec 1ad995b |
There was a problem hiding this comment.
Changes requested: the hit-area changes behave as described and their new tests pass, but the release note overstates what ships.
- Regression:
.changeset/hit-area-scroll-quiet.mdsays a tap still never reaches a neighbor that is nearer the finger and that a press no longer measures the page, yet during motion that no measuring pass saw the tap now goes to the control the browser hit-tests (isNearerAtClickinpackages/core/src/utils/hitArea.ts), and a press on a control a pass saw moving still reads every box atpointerdown, so please reword the changeset and the title to state those exceptions.
A changeset wording that fits:
On a phone, a press on a control at rest no longer measures the page, so a scroll that starts there does not wait. Hit areas no longer measure while the page scrolls or while a parent animates, such as a screen that slides in. While a control or its neighbor moves in an animation, the browser's own hit test decides the tap. No API changes.
Two optional fixes: a paused, finite ancestor animation holds a control's measurement forever, and the measuring pass's hold counts fades that the click check ignores.
A pass held a control under any finite parent animation. A paused one can stay paused, so the control was never measured, and a fade or a tint moves no box. The pass now waits only while a parent's running animation moves boxes, as the click's check reads motion. The release note states what ships: a press on a moving control still measures, and motion that starts after the last measurement leaves the tap to the browser's hit test.
|
/approve-spec 97a5ec3 |
There was a problem hiding this comment.
Changes requested: the click-time check, the scroll gate and the moving-ancestor hold behave as described, and their new cases fail on the base and pass here, but one case skips the nearer-neighbour check.
- Regression:
isNearerAtClick(packages/core/src/utils/hitArea.ts:1101) still counts paused animations as motion whilemeasure()treats them as at rest, so a tap on a control under a paused, finite animation, or nearer a neighbour under one, is no longer checked (in Chromium on this head, a touch 2 px from a link that moved under a Switch is swallowed while the row is still and turns the Switch on while the row holds a paused animation; the base checks that tap at the press); please keep only running animations there, asmeasure()does, ideally through one shared helper, and add click tests for a paused ancestor and a paused neighbour (the paused-neighbour half was already present at the previous head, and the earlier review missed it).
CI has not run on this draft head yet.
The pass treated a paused animation as at rest, but the click's check counted it as motion. A tap on a control under a paused animation, or nearer a neighbour under one, then went unchecked. One helper now gives both the running animations that move boxes.
|
/approve-spec 0bd3bda |
There was a problem hiding this comment.
Approved pending CI: CI has not run on this head yet, because the pull request is a draft; it already carries ci:run, so CI runs once it is marked ready for review.
The click-time check, the scroll gate and the moving-ancestor hold behave as described, and the click now uses the same running-only motion rule as the pass, so a tap under a paused animation is checked again (the two new click cases fail on the previous revision and pass here). The fallback while unseen motion moves a control or its neighbour is the gap an engineering owner accepted for this revision.
Non-blocking:
settlingAnimations's JSDoc (packages/core/src/utils/hitArea.ts:726-729) still says a paused hold is released, whichmovingAnimationsnow contradicts; see the inline suggestion.- A running ancestor animation that an app pauses later stays in
watch.heldBy, so presses on that control keep reading layout atpointerdownuntil a resize or content change re-measures it.
| * The finite animations running or held in `root` and its subtree. An endless | ||
| * one, such as a spinner, moves nothing that comes to rest. Core pauses an | ||
| * animation only inside a gesture, and the gesture ends it. So a watch that a | ||
| * paused animation holds is released. |
There was a problem hiding this comment.
Non-blocking (INV29): the last sentence no longer holds. The pass and the click now ignore paused animations (movingAnimations below says an app can leave one paused), and a running animation an app pauses mid-hold is never released from watch.heldBy. Suggested:
| * The finite animations running or held in `root` and its subtree. An endless | |
| * one, such as a spinner, moves nothing that comes to rest. Core pauses an | |
| * animation only inside a gesture, and the gesture ends it. So a watch that a | |
| * paused animation holds is released. | |
| * The finite animations running or held in `root` and its subtree. An endless | |
| * one, such as a spinner, never comes to rest. |
User impact
On a phone, a touch on any touch target reads every interactive element's box in its pointerdown. Hit areas also measure during a scroll and one frame after a NavigationStack push. These forced layouts add to the long tasks that turn a fling into a tap, which closes an open menu.
Problem and solution fit
The press check swallows a click whose tap a moved neighbor is nearer, but reads at the pointerdown. Passes also run during a scroll and under an animating ancestor, and a layer's open or close re-matches the page.
scrollendor 150 ms without a scroll event.Expected behavior and authority
spec:AST-094FR42: a coarse pointer's hit area grows toward 44 px and never takes a neighbor's tap, at no set time.spec:AST-110FR3: the scroll gate, page state, lives under a registered key. No record changes.Gap: motion no pass saw before the press goes unchecked; the browser's hit test takes that tap.
Smallest restoration
Evidence
Scope
Components:
utils/hitAreaandutils/touchHitArea, which Button, List, SegmentedControl, Switch and the other touch targets use.Testing
At 0bd3bda: a "Merge main" onto 18af3dc, then the fixes.
pnpm exec vitest run --project ui packages/core/src/utils/hitArea.test.ts packages/core/src/utils/touchHitArea.test.tsx: 74 pass. Without the click rule, two of the four motion cases fail; without the press rule, a third fails. At 1ad995b, a paused parent and a fading one held the pass: their two cases fail. At 97a5ec3, the click skipped a control under a paused parent and a neighbour under a paused animation: those two cases fail. On main'shitArea.ts, the five earlier cases fail.pnpm exec vitest run --project ui packages/core: 21,872 pass.pnpm test:node: 18,769 pass, withscripts/shared-identity.test.mjs, which failed on the merge.pnpm exec playwright test --config playwright.interaction.config.ts --project=chromium: every List spec, the hit-area specs, and the Button, ButtonGroup, Indicator, SegmentedControl, Switch, ToggleButton and Popover touch specs. 301 pass. In WebKit's CI container, at CI's one worker: 244 pass and 58 cases skip.Local gates: the core type check, strict ESLint, Prettier and
pnpm review:preagainst main (no findings). Device before/after clips come at landing.