Repository navigation
fix(Slider): sync its handler refs at commit - #10913
Conversation
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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
| 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
There was a problem hiding this comment.
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:
updateValueRefhas 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]
|
/approve-spec 96b3481 |
There was a problem hiding this comment.
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.mdsays 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'sonChangefix 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.
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.
|
/approve-spec dc01f9b |
There was a problem hiding this comment.
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.mdsays 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 committedonChangeEndwhen it is released"), or also claim the thumb drag'sonChangefix 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
fireChangeEndreads 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 thehandlePointerMovedependency 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.
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.
|
/approve-spec b490be1 |
There was a problem hiding this comment.
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
handlePointerMovedependency 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, testsSlider.test.tsx:2255and:2283. - Changeset, after a discarded render a finger dragging a thumb reports to the committed
onChange: verified,Slider.tsx:1290-1291, testuseSliderTouch.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
fireChangeEndreads 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.tsxaway from these lines, and the new tests merge clear of #7516: verified for the three ref lines and the test files; thehandlePointerMovedependency 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.mdclear;packages/core/src/Slider/Slider.tsxclear;packages/core/src/Slider/Slider.test.tsxclear;packages/core/src/Slider/useSliderTouch.test.tsxclear.
|
/approve-spec 221a7b8 |
There was a problem hiding this comment.
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, testsSlider.test.tsx:2255and:2283. - Changeset: after a discarded render, a finger dragging a thumb reports to the committed
onChange: verified,Slider.tsx:1290-1291, testuseSliderTouch.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
fireChangeEndreads 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.tsxaway from these lines, and the new tests merge clear of #7516: verified for the three ref lines, the tests and #4050; thehandlePointerMovedependency 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.mdclear;packages/core/src/Slider/Slider.tsxclear;packages/core/src/Slider/Slider.test.tsxclear;packages/core/src/Slider/useSliderTouch.test.tsxclear.
Render-time ref writes fixed, each read in a callback:
valuesRef,onChangeEndRefandupdateValueRefincore/Slider/Slider.tsx. Red-first: yes, three new tests fail on main, foronChangeEndRef,valuesRefandupdateValueRef.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
useRefcontract: do not writeref.currentduring rendering, except to initialize it.architecture:react-component-runtimeINV3 and INV17: a latest-value ref goes throughuseCommittedRef, and render writes no ref. INV4: no rendered value comes from a ref mutation.Smallest restoration
Three refs in
Slider.tsx. No API, visual or default changes.Evidence
Scope
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.
onChangeEndRefuseCommittedRefonChangeEnd, the committed callback reports the end, and the discarded one does not.valuesRefuseCommittedRefupdateValueRefuseCommittedRefuseSliderTouch.test.tsx: after a discarded render with anotheronChange, 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.tsxanduseSliderTouch.test.tsxrun whole against main's slider: the three new tests fail, and the other 128 pass.@astryxdesign/coretypecheck: 0 errors. ESLint and Prettier on the changed files: clean.#4050and#7516already conflict with main inSlider.tsx, away from these lines. The new tests sit at the end ofSlider.test.tsx, clear of#7516.useCommittedRef. The next commit moves the three refs onto it in place of the slider's layout effects.GestureHost.tschange, which the touch test imports. The change's own diff is unchanged.