Skip to content

fix(core): gesture hooks follow their element; recognizer plumbing is protected - #8315

Closed
vjeux wants to merge 1052 commits into
meta:mainfrom
vjeux:uikit/f2-hook-fixes
Closed

vjeux wants to merge 1052 commits into
meta:mainfrom
vjeux:uikit/f2-hook-fixes

Conversation

@vjeux

@vjeux vjeux commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Depends on #8309. Review only this pull request's change: vjeux/astryx@58dbb1a...2e77071

Why

Astryx's gesture hooks called a component's handlers at the wrong times. A recognizer unmounted mid-gesture reported cancelled from React's cleanup, and a press tracker's timer could call back after unmount, so a component could set state on something already gone. A touch that stopped a flicking list still counted as a press by default, and a component that changed a press tracker's options after mount was ignored.

What led to it

This is part of the UIKit-parity work on Astryx's touch components. Reviews of #8073, #8076, a context menu and a number input found these. React's rules for Astryx say a component's callback never fires from an Effect or from cleanup (architecture:react-component-runtime INV2, INV3).

Options and tradeoffs

  • Document the timing and let each component guard its own handlers: every caller repeats the guard, and one that forgets breaks quietly.
  • Recreate the tracker whenever an option changes: simple, but a press in progress would be dropped.
  • Fix it in the two hooks: silence them from the moment a component unmounts, and keep one tracker for the component's life that reads its options through refs.

Why this choice

The hooks are the only place every component passes through, so one fix covers all of them, and a press in progress survives an option change. Each recognizer's internal plumbing becomes protected, so components can no longer call it by accident; the arena and the host reach it through one internal accessor. A press stopping a flick no longer presses, because the brake now defaults to the host's.

How to check it

  1. Unmount a component while one of its gestures is mid-drag. Expected: its handler hears nothing after unmount.
  2. On a phone, flick a list of pressable rows and touch it to stop the scroll. Expected: no row activates.
  3. Change a press tracker's options while a finger is down on it. Expected: the press continues and the new options apply from the next read.
  4. Disable a control under a resting finger, then lift. Expected: the press ends silently, with no late activation.

Evidence

  • Each case fails before the change, including a type test showing the recognizer plumbing is no longer callable from outside a subclass.
  • The existing hook, arena and browser suites pass unchanged.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants