Skip to content

fix(Slider): sync its handler refs at commit - #10913

Merged
cixzhang merged 6 commits into
meta:mainfrom
vjeux:fix/slider-refs-at-commit
Nov 12, 2026
Merged

cixzhang merged 6 commits into
meta:mainfrom
vjeux:fix/slider-refs-at-commit

Conversation

@vjeux

@vjeux vjeux commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Render-time ref writes fixed, each read in a callback: valuesRef, onChangeEndRef and updateValueRef in core/Slider/Slider.tsx. Red-first: yes, three new tests fail on main, for onChangeEndRef, valuesRef and updateValueRef.

User impact

People who drag or press a Slider, in an app that renders with transitions. The slider kept its values, its change-end callback and its touch update in refs written while it rendered. A render React discards, as a suspended transition does, left its values there. A press on the track after a discarded render then reported the discarded value to the discarded callback.

Problem and solution fit

A write during render runs for every render, including the ones React throws away. These refs are read by the pointer and touch handlers and the change-end report, all after a commit, so they should hold the committed values.

Each ref now comes from useCommittedRef, Core's shared hook for latest-value refs. It writes at commit, before any layout effect, so the touch presentation's hook sees the committed values. The handlers that read the refs list them in their dependencies.

Expected behavior and authority

  • React's useRef contract: do not write ref.current during rendering, except to initialize it.
  • architecture:react-component-runtime INV3 and INV17: a latest-value ref goes through useCommittedRef, and render writes no ref. INV4: no rendered value comes from a ref mutation.
  • fix(lab): write latest-value refs at commit, not during render #10780, merged, made the same kind of change in Lab.

Smallest restoration

Three refs in Slider.tsx. No API, visual or default changes.

Evidence

  • Reproduction before the change: the three new tests fail on main a90e053, with the whole test files run.
  • Result after the change, at 221a7b8: they pass.
  • Representative unchanged path: the existing pointer, keyboard and touch tests still pass.
  • Regression test or other mutation-sensitive proof: each test fails while its ref is written during render.

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

All runs below are at this PR's head, 221a7b8.

Each test renders a slider at 50. A transition renders it again while a sibling suspends for good, so React never commits that render. A pointer then presses the middle of the track and lifts. The touch test drags a thumb with a finger instead.

Ref Now Red-first test
onChangeEndRef useCommittedRef After a discarded render with another onChangeEnd, the committed callback reports the end, and the discarded one does not.
valuesRef useCommittedRef After a discarded render at 80, the end reports 50.
updateValueRef useCommittedRef useSliderTouch.test.tsx: after a discarded render with another onChange, a finger dragging a thumb reports to the committed one. It also fails with only this ref written during render.
  • pnpm exec vitest run packages/core/src/Slider --project ui: 7 files, 177 tests pass.
  • Slider.test.tsx and useSliderTouch.test.tsx run whole against main's slider: the three new tests fail, and the other 128 pass.
  • @astryxdesign/core typecheck: 0 errors. ESLint and Prettier on the changed files: clean.
  • The open #4050 and #7516 already conflict with main in Slider.tsx, away from these lines. The new tests sit at the end of Slider.test.tsx, clear of #7516.
  • History: main merged at 7e7fbae on Nov 11, with no conflicts, so CI runs on a current base. The change's own diff is unchanged.
  • History: the merge of main 1740654 on Nov 12 has no conflicts and brings useCommittedRef. The next commit moves the three refs onto it in place of the slider's layout effects.
  • History: the merge of main a90e053 on Nov 12 has no conflicts and brings feat(core): one shared context request from a long press, a right click and Shift+F10 #8670's GestureHost.ts change, which the touch test imports. The change's own diff is unchanged.

The slider kept its values, its change-end callback and its touch
update in refs written while it rendered. A render React discards, as
a suspended transition does, left its values there. A press on the
track after a discarded render then reported the discarded value to
the discarded callback.

Each ref is now synced in a one-line layout effect, so the pointer and
touch handlers read the committed values.
@vercel

vercel Bot commented Nov 9, 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 Nov 12, 2026 12:39pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 9, 2026
@astracat-bot

astracat-bot Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 12, 2026, 12:48 PM UTC

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 221a7b8

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
Slider · Storybook 112.7 kB (+37 B) · 8.8 kB CSS (0) 2,447 (−2) ✓ · ✓ · ✓

Package size: @astryxdesign/core 7.39 MB packed (+18 B); no new dependencies.

Touched components checked; add ci:run-visual, ci:run-a11y or ci:run-rtl to run the full suites.


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

Approved pending CI: CI has not run on this head yet.

Moving the three ref writes in Slider.tsx into commit-time layout effects restores onChangeEnd's contract after a render React discards: both new tests fail on the base (the committed callback is never called, and the end reports 80 instead of 50) and pass here. There are no blocking findings. Next step: mark the pull request ready for review, then a maintainer adds the ci:run label so CI runs.

  • Optional: updateValueRef has no test of its own, and the gesture model it feeds drives every pointer's thumb drag, not only touch, so a test that drags a thumb with a mouse after a discarded render would lock it.

[Automated review]

@cixzhang

cixzhang commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

/approve-spec 96b3481

@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 10, 2026

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

Changes requested: the fix itself is sound, but the changeset describes a different fix from the one the tests prove.

  • Miss: .changeset/slider-refs-at-commit.md says a drag's end now reports the committed value to the committed callback, but the tests cover only a press on the track, and a thumb drag's end already did that before this change, so reword it to the track press, or also claim the thumb drag's onChange fix together with a test that drags a thumb after a discarded render.

Optional: updateValueRef has no test of its own; with only that ref reverted, every Slider test still passes, and the thumb-drag test above would lock it. CI has not run on this head yet because the pull request is a draft.

Automated review (maintainer link)

Comment thread .changeset/slider-refs-at-commit.md Resolved
The slider copied its values, its change-end callback and its update
into refs in three layout effects. The shared internal hook makes the
same writes at commit, so the slider calls it. The handlers list the
refs in their dependencies, and they read what they read before.
@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec dc01f9b

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

Changes requested: the fix itself reads correctly, but the changeset still describes a different fix from the one the tests prove.

  • Miss: .changeset/slider-refs-at-commit.md says a drag's end now reports the committed value to the committed callback, but the tests cover only a press on the track, and a drag that starts on a thumb already ended that way before this change, so reword it to the track press (for example "a press on the track reports the committed value to the committed onChangeEnd when it is released"), or also claim the thumb drag's onChange fix together with a test that drags a thumb after a discarded render.

Optional: no test drags a thumb after a discarded render, so a regression of updateValueRef would go unnoticed, and the new comments at Slider.tsx:905 and :1022 only restate the hook's name. CI has not run on this draft head.

Claims and files checked
  • Changeset, the values, change-end callback and touch update refs sync at commit: verified, Slider.tsx:906, :1023, :1261.
  • Changeset, after a discarded render a drag's end reports the committed value to the committed callback: false as worded; true for a press that starts on the track, while a drag that starts on a thumb already did this (finding above).
  • The three refs no longer write during render, and only callbacks read them: verified, Slider.tsx:1027-1028, :1234, :1269-1323.
  • A track press after a discarded render reported the discarded value to the discarded callback: verified from the base code, where fireChangeEnd reads refs the discarded render wrote.
  • The shared hook writes at commit, before any layout effect, so the touch hook sees committed values: verified, useCommittedRef.ts:35-37, useSliderTouch.ts:61-63.
  • The handlers that read the refs list them in their dependencies: verified, Slider.tsx:1037, :1252.
  • The cited rules (no ref writes during render; latest-value refs through the shared hook; no rendered value from a ref): verified against the current records.
  • A merged pull request made the same kind of change in Lab: verified (#10780).
  • No API, visual or default change: verified from the source diff.
  • The touch update ref has no new test, and only the gesture model reads it: verified, Slider.tsx:1293, :1318.
  • The two new tests fail on main, pass at this head, and each fails while its own ref is written during render: consistent with the code, and each test changes only the input its ref carries; not run here.
  • The whole Slider suite passes, and typecheck, ESLint and Prettier are clean: not run here.
  • #4050 and #7516 already conflict with main in Slider.tsx, away from these lines, and the new tests merge clear of them: the conflicts and the clean test-file merge are verified; one #7516 conflict already covers the handlePointerMove dependency list this change edits (:1252).
  • Both merges of main had no conflicts, and the last one brought in the shared hook: verified; each merge equals the automatic merge of its parents.
  • .changeset/slider-refs-at-commit.md: finding above.
  • packages/core/src/Slider/Slider.tsx: clear, apart from the two optional comment cleanups.
  • packages/core/src/Slider/Slider.test.tsx: clear; matches the changed refs and covers only the track press.

Automated review (maintainer link)

Comment thread packages/core/src/Slider/Slider.tsx Resolved
Comment thread packages/core/src/Slider/Slider.tsx Resolved
A finger dragging a thumb reports through the committed touch update.
The new test drags a thumb after a discarded render. It fails while
that update is written during render. The changeset now names the
track press and the thumb drag. Two comments that restated the hook's
name are gone.
@vjeux

vjeux commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Answers to the review of dc01f9b, at b490be1: the changeset now names the track press and the thumb drag. A new useSliderTouch.test.tsx case drags a thumb after a discarded render; it fails while the touch update is written during render.

@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec b490be1

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

Approved pending CI: CI has not run on this head yet; it starts when the pull request is marked ready for review.

The three refs now come from the shared committed-ref hook, the changeset names exactly what the tests prove (a track press and a finger's thumb drag after a discarded render), and the restating comments are gone. No blocking findings remain.

  • Optional: the description says #7516's conflicts with main sit away from these lines, but the handlePointerMove dependency list this change edits (Slider.tsx:1250) sits right after one of them, so that conflict grows by a line once this lands.
Claims and files checked
  • Changeset, the values, change-end callback and touch update refs sync at commit: verified, Slider.tsx:905, :1021, :1259.
  • Changeset, after a discarded render a track press reports the committed value to the committed onChangeEnd: verified, Slider.tsx:1023-1036, tests Slider.test.tsx:2255 and :2283.
  • Changeset, after a discarded render a finger dragging a thumb reports to the committed onChange: verified, Slider.tsx:1290-1291, test useSliderTouch.test.tsx:1017.
  • The three refs were written during render and are read only in callbacks: verified, Slider.tsx:1025-1026, :1232, :1267-1316.
  • A track press after a discarded render reported the discarded value to the discarded callback: verified from the base code, where fireChangeEnd reads refs the render wrote.
  • The shared hook writes at commit, before any layout effect, so the touch hook sees committed values: verified, useCommittedRef.ts:35-38, useSliderTouch.ts:61-63.
  • The handlers that read the refs list them in their dependencies: verified, Slider.tsx:1035, :1250.
  • The cited rules (no ref writes during render, latest-value refs through the shared hook, no rendered value from a ref): verified against the current records.
  • A merged pull request made the same kind of change in Lab: verified (#10780).
  • No API, visual or default change: verified from the source diff.
  • The three new tests fail on main and pass at this head, and each fails while its own ref is written during render: consistent with the code, since each test varies only its own ref's input; not run here.
  • The two test files hold 128 other tests that pass on main: the count matches (131 cases at this head); not run here.
  • The Slider suite (7 files, 177 tests), typecheck, ESLint and Prettier pass: not run here.
  • #4050 and #7516 conflict with main in Slider.tsx away from these lines, and the new tests merge clear of #7516: verified for the three ref lines and the test files; the handlePointerMove dependency list joins #7516's last conflict (note above).
  • Both merges of main had no conflicts, the second brought in the shared hook, and the next commit moved the refs onto it in place of layout effects: verified from the branch history.
  • Files: .changeset/slider-refs-at-commit.md clear; packages/core/src/Slider/Slider.tsx clear; packages/core/src/Slider/Slider.test.tsx clear; packages/core/src/Slider/useSliderTouch.test.tsx clear.

Automated review (maintainer link)

@vjeux
vjeux marked this pull request as ready for review November 12, 2026 11:29
@vjeux
vjeux marked this pull request as draft November 12, 2026 12:17
@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec 221a7b8

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

Approved pending CI: CI has not run on this head yet; it starts when the pull request is marked ready for review.

This head only merges main into the branch, and that merge touches none of the four changed files. The three refs come from the shared committed-ref hook, and the changeset names exactly what the tests prove: a track press and a finger's thumb drag after a discarded render. No blocking findings.

  • Optional: the description says #7516's conflicts with main sit away from these lines, but #7516's existing conflict spans handlePointerMove, including the dependency list this change edits (Slider.tsx:1250), so whoever rebases #7516 resolves one more line there.
Claims and files checked
  • Changeset: the values, change-end callback and touch update refs sync at commit: verified, Slider.tsx:905, :1021, :1259.
  • Changeset: after a discarded render, a track press reports the committed value to the committed onChangeEnd: verified, Slider.tsx:1023-1036, tests Slider.test.tsx:2255 and :2283.
  • Changeset: after a discarded render, a finger dragging a thumb reports to the committed onChange: verified, Slider.tsx:1290-1291, test useSliderTouch.test.tsx:1017.
  • The three refs were written during render and are read only in callbacks: verified, Slider.tsx:1025-1026, :1232, :1267-1316.
  • A track press after a discarded render reported the discarded value to the discarded callback: verified from the base code, where fireChangeEnd reads refs the render wrote.
  • The shared hook writes at commit, before any layout effect, so the touch hook sees committed values: verified, useCommittedRef.ts:35-37, useSliderTouch.ts:61-63.
  • The handlers that read the refs list them in their dependencies: verified, Slider.tsx:1035, :1250.
  • The cited rules (no ref writes during render, latest-value refs through the shared hook, no rendered value from a ref): verified against the current records.
  • A merged pull request made the same kind of change in Lab: verified (#10780).
  • No API, visual or default change: verified from the source diff.
  • The three new tests fail on main and pass at this head, each failing while its own ref is written during render: the two track-press tests failed on main in an earlier run on an older revision of this pull request; at this head, not run here.
  • The two test files' other 128 tests, the Slider suite (7 files, 177 tests), typecheck, ESLint and Prettier pass: not run here.
  • #4050 and #7516 conflict with main in Slider.tsx away from these lines, and the new tests merge clear of #7516: verified for the three ref lines, the tests and #4050; the handlePointerMove dependency list sits inside #7516's existing conflict (note above).
  • The three merges of main had no conflicts; the second brought in the shared hook and the next commit moved the refs onto it; the third brought in the gesture host change the touch test imports and left the change's own diff unchanged: verified from the branch history.
  • Files: .changeset/slider-refs-at-commit.md clear; packages/core/src/Slider/Slider.tsx clear; packages/core/src/Slider/Slider.test.tsx clear; packages/core/src/Slider/useSliderTouch.test.tsx clear.

Automated review (maintainer link)

@vjeux
vjeux marked this pull request as ready for review November 12, 2026 12:53
@cixzhang
cixzhang merged commit 73584cf into meta:main Nov 12, 2026
129 checks passed
@vjeux
vjeux deleted the fix/slider-refs-at-commit branch November 12, 2026 13:40

This branch was successfully deployed

1 active deployment
Preview — 221a7b8b Deployed Nov 12, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) 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