Repository navigation
fix(usePanGesture): write the onPan ref at commit - #10090
Conversation
usePanGesture kept the latest onPan in a ref written during render. A render React discards, as a suspended transition does, left its onPan there, so a drag on the committed element called a listener from a render that never committed. The hook now writes the ref in a layout effect, as useGestureRecognizer already does.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
| Package | Where | Signature | Usage | |
|---|---|---|---|---|
| + | cli |
./api · Types · type SearchResultEntry |
deprecated?: ComponentDeprecation | undefined |
import type {SearchResultEntry} from '@astryxdesign/cli/api'; const x: SearchResultEntry = {deprecated: …} |
| + | cli |
./authoring · Types · interface ComponentDeprecation |
interface ComponentDeprecation |
import type {ComponentDeprecation} from '@astryxdesign/cli/authoring' |
| + | cli |
./authoring · Types · interface MultiComponentDoc |
deprecated?: ComponentDeprecation |
import type {MultiComponentDoc} from '@astryxdesign/cli/authoring'; const x: MultiComponentDoc = {deprecated: …} |
| + | cli |
./authoring · Types · interface SingleComponentDoc |
deprecated?: ComponentDeprecation |
import type {SingleComponentDoc} from '@astryxdesign/cli/authoring'; const x: SingleComponentDoc = {deprecated: …} |
| + | cli |
./doc · Types · interface ComponentBaseDoc |
deprecated?: ComponentDeprecation |
import type {ComponentBaseDoc} from '@astryxdesign/cli/doc'; const x: ComponentBaseDoc = {deprecated: …} |
| + | cli |
./doc · Types · interface SubComponentDoc |
deprecated?: ComponentDeprecation |
import type {SubComponentDoc} from '@astryxdesign/cli/doc'; const x: SubComponentDoc = {deprecated: …} |
| + | cli |
./doc · Also exported from an earlier entry point · ComponentDeprecation |
ComponentDeprecation (./authoring) |
import {ComponentDeprecation} from '@astryxdesign/cli/doc' |
| + | cli |
./template · Also exported from an earlier entry point · ComponentDeprecation |
ComponentDeprecation (./authoring) |
import {ComponentDeprecation} from '@astryxdesign/cli/template' |
| ~ | cli |
./api · Functions · function search |
function search: (query: string, options?: { cwd?: string | undefined; type?: "template" | "component" | "hook" | "theme" | "doc" | undefined; limit?: number | undefined }) => Promise<SearchResponse> → function search: (query: string, options?: { cwd?: string | undefined; type?: "template" | "component" | "doc" | "theme" | "hook" | undefined; limit?: number | undefined }) => Promise<SearchResponse> |
import {search} from '@astryxdesign/cli/api'; search(…) |
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
There was a problem hiding this comment.
Approved pending CI: CI has not run on this head yet. Moving the onPan ref write to commit keeps a discarded render's listener away from the next drag, and the new suspended-transition test fails without the fix and passes with it.
Next: mark the pull request ready for review, and a maintainer adds the ci:run label so CI runs on the fork branch.
- Optional: the sentence added to the file header in
usePanGesture.tsrepeats the reason the inline comment already gives and pushes the header past about 12 lines; consider dropping it.
[Automated review]
| * ref, so a new function each render re-creates nothing. The hook writes | ||
| * the ref at commit, so a render React discards leaves no listener. A drag | ||
| * costs no React render. |
There was a problem hiding this comment.
Non-blocking: this sentence repeats the reason the comment at lines 48-49 gives, and the header grows to 14 lines, past the about-12-line header limit in architecture:knowledge-contracts INV29. Keeping the original two lines leaves the reason in one place:
* ref, so a new function each render re-creates nothing. A drag costs no
* React render.There was a problem hiding this comment.
Approved pending CI: the CI workflow is still running on this head. Moving the onPan ref write to commit keeps a discarded render's listener away from the next drag, and the new suspended-transition test fails without the fix and passes with it.
- Optional: the sentence added to the file header in
usePanGesture.tsrepeats the reason the inline comment already gives and pushes the header past about 12 lines; consider dropping it.
[Automated review]
User impact
usePanGesturecould hand a drag to anonPanfrom a render React threw away. A transition that suspends is one such render. The committed element then ran a listener its screen never showed, with that render's props and state.Problem and solution fit
onPaninto a ref during render. React can render and then discard that render, and the ref keeps the discarded listener.The fix copies
onPaninto the ref at commit. A layout Effect runs only for renders React commits, and a drag's events arrive only after a commit.Expected behavior and authority
spec:AST-107FR6: "the hook delegates entirely to its factory and has no behavior of its own." Calling a listener that no committed render passed is behavior of its own.architecture:react-component-runtimeINV4: ref-backed coordination must preserve the current API contract.useRefreference: do not writeref.currentduring rendering, except to initialize it.Smallest restoration
onPanRef.current = onPanmoves intouseIsomorphicLayoutEffect, Core's server-safe layout Effect. Its comment says why it runs at commit. There is no API, timing, or visual change.Core has no shared latest-ref helper.
useGestureRecognizer(lines 105–107),PickerWheelandMarkdowneach write their listener's ref in a layout Effect, and this follows that pattern.review:preflags such an Effect as a copy into a ref (INV3); here the copy at commit is the fix.useEffectEventneeds React 19.2, and Core supports 19.0.The changeset is
[chore] Internal:because the hook has not shipped yet.Evidence
bank/f2/pan-onpan-commit-main-red-arm). The discarded render'sonPanreceived the drag's 5 events.onPanreceivesbegan,changedandended, and the discarded one receives nothing.createPanGesture.test.tsx.Scope
Testing
Local gates at a4d8303, one commit on main 0a1e6a0.
npx vitest run --project ui packages/core/src/gestures/__tests__/createPanGesture.test.tsx: 15 passed. The new case fails on main without the fix.tsc --project packages/core/tsconfig.json --noEmit, strict ESLint, Prettier andpnpm check:changesets: clean.node scripts/pre-review.mjs --base main: one finding, the Effect that copies into a ref, answered under Smallest restoration.