Skip to content

fix(Slider): a drag belongs to the pointer that started it - #8152

Merged
cixzhang merged 2 commits into
meta:mainfrom
vjeux:uikit/c03-slider-one-pointer
Oct 24, 2026
Merged

cixzhang merged 2 commits into
meta:mainfrom
vjeux:uikit/c03-slider-one-pointer

Conversation

@vjeux

@vjeux vjeux commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Siblings on the same pointer handlers: #8151 (coincident range thumbs) and #7516 (pointer selection of an off-grid max). Whichever lands later is rebased.

User impact

On a touch screen, a second finger that touches a Slider during a drag (a palm, a resting thumb) takes the drag over. The value jumps to that finger. When it lifts, onChangeEnd commits a value the user never chose, and the first finger stops moving the slider. Now the drag belongs to the finger that started it, and two fingers can still drag two sliders.

Problem and solution fit

  1. Why it happens. The handlers ignore pointerId: any pointerdown starts a drag, any pointermove drives it, and any pointerup ends it.
  2. Why it harms the task. The value no longer follows the hand that moves it.
  3. Why it matters. Owners commit on onChangeEnd, so a stray touch commits a wrong value.

The slider ignores every other pointer until the drag's own pointer lifts or is cancelled. A capture lost without an up also ends the drag. Otherwise a drag left open would block every later press.

Expected behavior and authority

  • component:Slider FR5: onChangeEnd fires once, when the drag is released or cancelled.
  • Touch reference: a UIKit control tracks one touch, because UIView.isMultipleTouchEnabled defaults to false (Apple).

Smallest restoration

The change is in Slider.tsx only. A ref holds the drag's pointerId, and a lostpointercapture listener ends the drag. There is no new prop.

Evidence

Real touch in Chromium (phone emulation, two touch points). Finger A grabs the thumb at 50, and finger B lands on the track at 10 %:

Step main This branch
A drags +30 px 61 61
B lands 7 61
A drags +40 px, B moves 9 64
B lifts onChangeEnd(9) nothing
A drags +60 px, lifts stays 9 71, onChangeEnd(71)
  • Unchanged paths: two fingers dragging two sliders, and every existing single-pointer test.
  • Regression test: "one pointer per drag" in Slider.test.tsx. Its second-finger and lost-capture cases fail on main.

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Testing

  • pnpm exec vitest run --project ui packages/core/src/Slider: 3 files, 98 tests pass. With main's Slider.tsx, 2 of the 3 new cases fail.
  • pnpm -F @astryxdesign/core typecheck, eslint and prettier on the touched files, and the pre-commit checks: pass.
  • Chromium, phone viewport, two touch points: the table above.

A second finger that lands on the slider, moves or lifts during a drag no
longer moves the value, takes over the drag or ends it (a control tracks one
touch, as UIKit's isMultipleTouchEnabled = false). A drag whose pointer
capture is lost without an up also ends, so the slider never stays held by a
pointer that is gone.
@vercel

vercel Bot commented Oct 24, 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 Oct 24, 2026 1:50pm UTC

Request Review

@astracat-bot

astracat-bot Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 24, 2026, 2:16 PM UTC

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

One change is needed before approval: the lostpointercapture listener is bound once to the control node (Slider.tsx:837-846), so when that node is replaced, as a FormLayout direction change does, a drag in progress never ends and the slider then refuses every later pointer press, where main recovers on the next tap. Listening on the control's owner document (track.ownerDocument) instead fixes both the before-drag and mid-drag cases with the existing tests still passing, and a regression case for the replaced node would keep it fixed. Otherwise the fix does what it says: tying a drag to the pointer that started it restores onChangeEnd to the drag's own release, and it holds up with two fingers, mouse plus finger, and plain mouse, pen and touch drags.

[Automated review]

Comment thread packages/core/src/Slider/Slider.tsx Outdated
}
const onLostCapture = (event: globalThis.PointerEvent) =>
endDrag(event.pointerId);
track.addEventListener('lostpointercapture', onLostCapture);

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.

This listener lives on the node trackRef holds when the Effect runs, and the Effect only re-runs when endDrag changes. A FormLayout direction change re-parents Field's children and replaces that node while the Slider stays mounted. In Chromium, switching it mid-drag fires lostpointercapture at the document, and a finger lifted away from the slider sends pointerup to html, so the drag stays open and handlePointerDown (L752-754) refuses every later pointer press; main recovers on the next tap. Listening on the owner document fixes it (the Slider suite still passes, and both the before-drag and mid-drag replacement cases recover):

const doc = track.ownerDocument;
doc.addEventListener('lostpointercapture', onLostCapture);
return () => doc.removeEventListener('lostpointercapture', onLostCapture);

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

Modified Components

Slider (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 979 -
Complexity N/A Very High (150) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.9KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

46 of 496 shot(s) changed.

A change here is a question, not a failure: check whether the after is the
picture you intended. Record that review on the PR. Baseline maintenance is an
explicit dispatch of CI; this report never rewrites the baseline or adds a release gate.

component story theme mode pixels
Selector Indicator Space Bottom Sheet Narrow End RTL neutral light 753,933
Selector Indicator Space Bottom Sheet Wide Start neutral light 740,072
Chat Full AI Chat probe light 230,823
Chat Full AI Chat probe dark 229,805
RichTextEditor Markdown parity: side by side probe dark 94,866
RichTextEditor Markdown parity: side by side probe light 89,762
Collapsible Dividers probe dark 66,445
Collapsible Dividers probe light 66,445
Chat Default neutral dark 36,304
Chat Default neutral light 35,767
Chat Empty State probe light 23,531
Chat Empty State probe dark 22,622
ChatAutoScroll Scroll Behavior Comparison neutral dark 15,378
ChatAutoScroll Scroll Behavior Comparison neutral light 14,107
Chat With Attachments probe light 13,406
Chat With Attachments probe dark 11,232
ProgressBar With Target Mark probe dark 7,895
ProgressBar With Target Mark probe light 7,895
Markdown Default neutral dark 7,573
Markdown Default neutral light 7,566

and 26 more.


Generated by PR Enrichment workflow | Storybook | Sandbox | 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.

Recommended for approval: a drag now belongs to the pointer that started it, and moving the lost-capture listener to the owner document fixes the earlier case where a mid-drag FormLayout change left the slider refusing presses; both hold with real mouse, touch and pen input in Chromium. One optional follow-up: the replaced-node test switches FormLayout to horizontal, which keeps the control node, so horizontal-labels would make it exercise the replacement its name describes. The failing pr-a11y job runs a test file added to main after this branch was cut, so a rebase should clear it.

[Automated review]

const before = trackOf(screen.getByRole('slider'));
fireEvent.pointerDown(before, {clientX: 136, clientY: 10, pointerId: 1});

rerender(<InLayout direction="horizontal" />);

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.

This switch keeps the control node: Field re-parents its children only for horizontal-labels (Field.tsx:240-241), and vertical and horizontal share one branch, so the old node is still connected when lostpointercapture reaches the document. The case proves a document-level end, not the replacement its name describes. With horizontal-labels the node is replaced and the case still passes on this head:

function InLayout({direction}: {direction: 'vertical' | 'horizontal-labels'}) {
  // …
}
// …
rerender(<InLayout direction="horizontal-labels" />);

@cixzhang
cixzhang merged commit 655b543 into meta:main Oct 24, 2026
63 of 64 checks passed
@vjeux
vjeux deleted the uikit/c03-slider-one-pointer branch October 24, 2026 14:36
cixzhang added a commit that referenced this pull request Oct 24, 2026
…ag (#8284)

Follow-up to #8152.

## User impact

Every Slider on a page, desktop included, kept a document-level `lostpointercapture` listener for as long as it was mounted, although the listener only matters while a drag is in progress. A page with many sliders paid for that many always-on document listeners, and each one ran on every capture loss anywhere on the page. After this change the listener exists only for the duration of a drag. Dragging behaves exactly as before, including the case #8152 fixed: when the control node is replaced mid-drag (a FormLayout direction change), losing the capture still ends the drag, and the slider answers the next press.

## Problem and solution fit

- Why does it happen? #8152 moved the lost-capture listener from the control node to the owner document so a replaced node stays covered, and attached it in an Effect for the component's lifetime.
- Why does it hurt? `architecture:react-component-runtime` INV5/INV7 keep document-level subscriptions scoped to the interaction that needs them.
- Fix: attach the document listener in the pointer-down handler that starts the drag and remove it when the drag ends (pointer up, cancel, or lost capture). An unmount mid-drag also removes it.

## Expected behavior and authority

- `architecture:react-component-runtime` INV5/INV7 (current): document-level listeners are scoped to the interaction that needs them.
- `component:Slider` FR5 (current): an interaction ends when its drag is released; unchanged.

## Smallest restoration

- `Slider.tsx`: the listener is added in `handlePointerDown` and removed in `endDrag` (and on unmount); the lifetime Effect is gone. No API, prop, default, DOM or visual change.

## Evidence

- New test "holds a document listener only while a drag is in progress": no listener while idle, one added on pointer down and the same one removed on pointer up, and a second drag's listener removed on unmount. It fails on `main`.
- The replaced-node test now switches FormLayout to `horizontal-labels`, which replaces the control node (the previous `horizontal` kept it), and still passes: the drag ends and the next press works.
- All Slider tests pass (100).

## Scope

- [x] One defect is restored.
- [x] Separable contradictory or unsettled tagalongs were removed or split.
- [x] No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
- [x] Public text and artifacts contain no internal Meta context.

## Testing

- `pnpm vitest run packages/core/src/Slider`: 100 passed.
- `tsc --noEmit` for core; strict eslint; prettier.

This branch was successfully deployed

1 active deployment
Preview — 2950669d Deployed Oct 24, 2026 by vercel[bot]
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants