Skip to content

fix(Slider): hold the lost-capture document listener only during a drag - #8284

Merged
cixzhang merged 1 commit into
mainfrom
fix/slider-lost-capture-drag-scope
Oct 24, 2026
Merged

cixzhang merged 1 commit into
mainfrom
fix/slider-lost-capture-drag-scope

Conversation

@cixzhang

Copy link
Copy Markdown
Contributor

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? fix(Slider): a drag belongs to the pointer that started it #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

  • 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 vitest run packages/core/src/Slider: 100 passed.
  • tsc --noEmit for core; strict eslint; prettier.

@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 6:24pm 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, 6:50 PM UTC

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

Previews ready: Storybook and Sandbox were built with this PR's docsite. CI evidence will be added when available.

View Storybook for this PR · View Sandbox for this PR

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

Looks good to merge: the lost-capture listener now lives only for the drag, and drags end exactly as before. The new test fails on main and catches either cleanup being removed, and in Chromium idle sliders hold no document listener while drag results, including the FormLayout node replacement from #8152, match main. As a separate follow-up, a control node replaced before the browser has applied pointer capture fires no lostpointercapture, so that release reports no onChangeEnd; main behaves the same.

[Automated review]

@cixzhang
cixzhang merged commit bf80690 into main Oct 24, 2026
64 checks passed
@github-actions
github-actions Bot deleted the fix/slider-lost-capture-drag-scope branch October 25, 2026 06:20

This branch was successfully deployed

1 active deployment
Preview — d399bf52 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.

1 participant