Repository navigation
fix(BottomSheet): keep snap points and the reentry in state - #10873
Conversation
BottomSheetPanel copied its snap points, and whether an entrance brings back a retained sheet, into refs written during render. The sheet's gestures copied the stop resolver the same way. A render React discards, as a suspended transition does, left its values there, so a released drag could rest at a stop the sheet never committed. The snap points are now state, kept with their key. The entrance is state adjusted as the panel's state changes. The gestures sync the resolver in a layout effect declared before the re-anchor that reads it.
|
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 |
|---|---|---|---|
| BottomSheet | 70.0 kB (+9 B) · 7.7 kB CSS (0) | — | ✗ · ✓ · — |
| BottomSheetSwitcher | 18.7 kB (0) · 3.4 kB CSS (0) | — | ✗ · ✓ · — |
| DateTimeInput | 218.0 kB (+33 B) · 19.1 kB CSS (0) | — | — · — · — |
21 more components
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| TimeInput | 168.9 kB (+27 B) · 16.4 kB CSS (0) | — | — · — · — |
| DateInput | 195.5 kB (+25 B) · 17.4 kB CSS (0) | — | — · — · — |
| PowerSearch | 302.2 kB (+17 B) · 24.7 kB CSS (0) | — | — · — · — |
| Table | 131.7 kB (+2 B) · 18.7 kB CSS (0) | — | — · — · — |
| lab/CommentThread | 359.2 kB (+2 B) · 2.4 kB CSS (0) | — | — · — · — |
| richtext/RichTextEditorToolbar | 285.4 kB (+2 B) · 454 B CSS (0) | — | — · — · — |
| Popover | 96.3 kB (+1 B) · 14.6 kB CSS (0) | — | — · — · — |
| TableHeaderCell | 114.6 kB (+1 B) · 18.0 kB CSS (0) | — | — · — · — |
| DropdownMenu | 103.0 kB (0) · 17.9 kB CSS (0) | — | — · — · — |
| Markdown | 194.7 kB (0) · 21.1 kB CSS (0) | — | — · — · — |
| Pagination | 116.2 kB (0) · 18.2 kB CSS (0) | — | — · — · — |
| Selector | 106.0 kB (0) · 17.9 kB CSS (0) | — | — · — · — |
| TableCell | 115.1 kB (0) · 18.3 kB CSS (0) | — | — · — · — |
| lab/ChatReactionBar | 112.8 kB (0) · 1.1 kB CSS (0) | — | — · — · — |
| lab/CommentComposer | 157.4 kB (0) · 1.9 kB CSS (0) | — | — · — · — |
| ContextMenu | 113.8 kB (−1 B) · 17.8 kB CSS (0) | — | — · — · — |
| MoreMenu | 103.3 kB (−1 B) · 17.9 kB CSS (0) | — | — · — · — |
| MultiSelector | 100.2 kB (−1 B) · 17.2 kB CSS (0) | — | — · — · — |
| Tokenizer | 102.6 kB (−1 B) · 19.5 kB CSS (0) | — | — · — · — |
| lab/ChatEmojiPicker | 111.6 kB (−1 B) · 773 B CSS (0) | — | — · — · — |
| lab/Comments | 366.2 kB (−1 B) · 2.5 kB CSS (0) | — | — · — · — |
Visual changes: 2 snapshots in 1 component
A change is a question for the reviewer, not a failure.
| Component · story | Before | After | Diff |
|---|---|---|---|
| BottomSheet · Text Only (neutral, dark) | ![]() |
![]() |
![]() |
| BottomSheet · Text Only (neutral, light) | ![]() |
![]() |
![]() |
Package size: @astryxdesign/core 7.47 MB packed (+78 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; it runs once the pull request is marked ready for review and a maintainer adds the ci:run label.
Keeping the snap points in state and syncing the drag's stop resolver at commit means a render React discards no longer moves the stop a released drag rests at; the new test fails without either half of the change and passes with both.
Two optional comment rewrites are suggested inline (non-blocking).
[Automated review]
|
/approve-spec f640d2b |
|
/approve-spec 1c7a9df |
There was a problem hiding this comment.
Approved pending CI: CI has not run on this head yet; it runs once the pull request is marked ready for review (the ci:run label is already on it).
Keeping the snap points in state and syncing the drag's stop resolver at commit means a render React discards no longer moves the stop a released drag rests at. The new test fails on the base and with either half of the change alone, and passes on this head after the merge from main.
The two earlier inline comment-style suggestions still apply and are non-blocking.
The gestures copied the snap-height resolver into a ref in a layout effect declared before the re-anchor effect. The shared internal hook writes it at commit before any layout effect, so the gestures call it. The detent callback lists the ref in its dependencies.
|
/approve-spec ab6da7a |
There was a problem hiding this comment.
Changes requested: keeping the snap points and the entrance flag in state, and reading the stop resolver through useCommittedRef, is the right fix, but three things need to change first.
- Newly live check: the layout effect at
BottomSheetPanel.tsx:815-819, which this pull request edits, still copiesonMotionStart,onMotionCompleteandonScrimFadeDurationinto refs in a per-component Effect, which the runtime architecture's INV3 now routes throughuseCommittedRef, so replace those three refs withuseCommittedRef(...)and delete the Effect, as this pull request already does forsnapHeightsRef. - The description's opening line says
snapPointsRefand the tworeactivatedEntranceRefwrites are read during render, but on the current basesnapPointsRefis read only inside the resolver at call time andreactivatedEntranceRefonly in the motion layout effect, so please reword it. - The Testing table says the entrance flag's reader runs only when the motion changes, but the motion layout effect also re-runs when
isCrossFadeorplayedDragExitchanges and when a Suspense boundary shows the sheet again (see the comment atBottomSheetPanel.tsx:1018-1021), so please reword that row or add a test for the discarded-render path.
Two small non-blocking suggestions are inline, and the two earlier comment-style suggestions still apply.
Claims and files checked
- Changeset: snap points and the entrance flag live in state, the resolver syncs at commit, and a discarded render no longer moves where a release rests. Verified in code (
BottomSheetPanel.tsx:797-813,:840-862;useSheetGestures.ts:716); a test run has not yet confirmed the behaviour. - The panel's snap-points ref and both entrance-ref writes are read during render. False (base
BottomSheetPanel.tsx:839,:1017). - The gestures' resolver ref is read in a callback. Verified (
useSheetGestures.ts:894). - Main copied the snap points and the resolver into refs during render, and a discarded render left its values there. Verified (base
BottomSheetPanel.tsx:828-829,useSheetGestures.ts:717-718). - Main kept the entrance flag in a ref written during render. Verified (base
BottomSheetPanel.tsx:798,:800). - The snap points are keyed state, so the resolver's identity changes only with the stops. Verified (
BottomSheetPanel.tsx:841-862). - The resolver comes from
useCommittedRef, written before the re-anchor's layout effect reads it. Verified (insertion Effect inuseCommittedRef.ts;useSheetGestures.ts:1016-1022). - The entrance flag is state that the motion effect reads. Verified (
BottomSheetPanel.tsx:797-813,:1033,:1097). - The cited runtime rules: no render-time ref writes, latest-value refs through
useCommittedRef, no rendered value from a ref mutation. Verified against the current runtime architecture record. - An earlier Lab pull request made the same kind of change. Verified (#10780, merged).
- Three refs change in the panel and one in the gestures, with no API, visual or default change. Verified (diff; package exports unchanged).
- The entrance flag's reader runs only when the motion changes, so it needs no new test. False (
BottomSheetPanel.tsx:1018-1021,:1097). - The new test fails on main (784px instead of 448px), passes at this head, and also fails with only the panel's change. Unverified: needs a test run; the base code path reads the discarded stops.
- The BottomSheet suite passes (14 files, 616 tests), and the existing snap-point tests pass, including a re-anchor under a resting sheet. Unverified: needs a test run.
- Typecheck, ESLint and Prettier are clean. Unverified: needs a run.
- History: the first merge of main had no conflicts, the second had one in
BottomSheetPanel.tsxresolved to the keyed state with its lint disable dropped, and the next commit moves the resolver ontouseCommittedRef. Verified (merge history; no lint disable remains at the memo). - Scope: one defect restored, no hidden API, visual, default or interaction change, no internal context. Verified.
.changeset/bottom-sheet-snap-points-in-state.md: clear.packages/core/src/BottomSheet/BottomSheet.test.tsx: clear (read; red-first not yet confirmed by a run).packages/core/src/BottomSheet/BottomSheetPanel.tsx: the Effect finding above; non-blocking notes inline.packages/core/src/BottomSheet/useSheetGestures.ts: clear; one non-blocking comment note inline.
A layout effect copied onMotionStart, onMotionComplete and onScrimFadeDuration into refs. They now come from useCommittedRef, as INV3 asks, listed in the deps of the effects that read them. The scrim fade's cleanup reads the callback through a function its effect declares, so the host's current callback hears the fade end. The entrance flag's update drops a branch that cannot run, and three comments keep only their reasons.
|
/approve-spec 9985aa8 |
There was a problem hiding this comment.
Approved pending CI: CI has not run on this head yet; it runs once the pull request is marked ready for review (the ci:run label is already on it).
Keeping the snap points and the entrance flag in state, and reading the stop resolver and the three motion callbacks through useCommittedRef, keeps a released drag on the committed stop after a discarded render, and every point from the last review is addressed. CI's run of the BottomSheet suite, typecheck and lint is the remaining check.
Claims and files checked
- Changeset: the sheet keeps its snap points and its reactivated entrance in state and syncs the drag's stop resolver at commit, so a discarded render no longer changes where a released drag rests. Verified in code (
BottomSheetPanel.tsx:797-809,:829-851;useSheetGestures.ts:715). - The panel's snap-points ref, read by the stop resolver, and two writes of the entrance ref, read by the motion layout effect, were written during render. Verified (base
BottomSheetPanel.tsx:828-829,:839,:798,:800,:1017). - The gestures' resolver ref was written during render and read in a callback. Verified (base
useSheetGestures.ts:717-718; head:893). - A render React discards left its values in those refs, so a released drag could rest at a stop the sheet never committed. Verified in code: React re-attempts the suspended render after each commit, and each attempt rewrote both refs on the base.
- The snap points are keyed state, so the resolver's identity changes only with the stops. Verified (
BottomSheetPanel.tsx:829-851). - The resolver comes from
useCommittedRef, written at commit before the re-anchor's layout effect reads it. Verified (insertion Effect inuseCommittedRef.ts;useSheetGestures.ts:715,:1015-1021). - The entrance flag is state adjusted as the panel's state changes, and the motion effect reads it. Verified (
BottomSheetPanel.tsx:797-809,:1023,:1091). - The three motion callbacks come from
useCommittedRefinstead of a layout effect's copy. Verified (BottomSheetPanel.tsx:788-790; the copy effect is gone). - The cited rules: no ref writes during render except initialization, state adjusted while rendering for previous-render information, latest-value refs through the shared hook, and no rendered value from a ref mutation. Verified against the current runtime architecture record.
- Six refs change in the panel, three of them the motion callbacks, and one in the gestures, with no API, visual or default change. Verified (diff; the BottomSheet exports are unchanged).
- The new test fails on main (784px instead of 448px), passes at this head, and also fails with only the panel's change. Consistent with the code on both sides; CI runs the test.
- The BottomSheet suite passes (14 files, 616 tests), including the existing snap-point and re-anchor tests, and typecheck, ESLint and Prettier are clean. Left to CI, which runs them before merge.
- No new test for the entrance flag: a discarded render's state adjustment is discarded with it, and the existing reactivation test covers the flag. Verified (
BottomSheetPanel.test.tsx:530). - No new test for the motion callbacks: the old layout effect already wrote them at commit. Verified (base
BottomSheetPanel.tsx:803-808). - History: the first merge of main had no conflicts; the second had one in
BottomSheetPanel.tsx, resolved to the keyed state with its lint disable dropped; the next commit moved the resolver ontouseCommittedRef. Verified (merge history; no lint disable left in the panel). - Scope: one defect restored, no hidden API, visual, default or interaction change, no internal context. Verified.
.changeset/bottom-sheet-snap-points-in-state.md: clear.packages/core/src/BottomSheet/BottomSheet.test.tsx: clear.packages/core/src/BottomSheet/BottomSheetPanel.tsx: clear.packages/core/src/BottomSheet/useSheetGestures.ts: clear.
|
/approve-spec 1764d83 |
There was a problem hiding this comment.
Approved pending CI: CI has not run on this head yet; it runs once the pull request is marked ready for review (the ci:run label is already present).
The only change since the last review is a merge of main that leaves this pull request's own diff unchanged; the animator option it brings in is opt-in and BottomSheet does not use it. One optional follow-up remains: BaseTypeahead.tsx (lines 823-825) still cites BottomSheetPanel's layout-effect onMotionStartRef as its precedent, which this change removes.
Claims and files checked
- Changeset: the sheet keeps its snap points and its reactivated entrance in state and syncs the drag's stop resolver at commit. Verified (
BottomSheetPanel.tsx:797-809,:829-851;useSheetGestures.ts:715). - Changeset: a discarded render that changes
snapPointsno longer changes where a released drag rests. Verified: the stops change only at commit, and the other render-time values the release reads do not takesnapPoints(useSheetGestures.ts:631-632,:707-712). - The panel's snap-points ref, read by the stop resolver, and two writes of the entrance ref, read by the motion layout effect, were written during render; so was the gestures' resolver ref, read in a callback. Verified (base
BottomSheetPanel.tsx:828-829,:798,:800,:1017; baseuseSheetGestures.ts:717-718). - A discarded render left its values in those refs, so a released drag could rest at a stop the sheet never committed. Verified in code for snap points: the retried transition render rewrote both refs on the base.
- The snap points are keyed state, so the resolver's identity changes only with the stops. Verified (
BottomSheetPanel.tsx:829-851). - The resolver comes from
useCommittedRef, written at commit before the re-anchor's layout effect reads it. Verified (useCommittedRef.ts:35-38;useSheetGestures.ts:715,:1015-1021). - The entrance flag is state adjusted as the panel's state changes, and the motion effect reads it. Verified (
BottomSheetPanel.tsx:797-809,:1023,:1091). - The three motion callbacks come from
useCommittedRefinstead of a layout effect's copy. Verified (BottomSheetPanel.tsx:788-790; the copy effect is gone). - The cited rules: no ref writes during render except initialization, state adjusted while rendering for previous-render information, latest-value refs through the shared hook, and no rendered value from a ref mutation. Verified against the current runtime architecture record.
- Six refs change in the panel, three of them the motion callbacks, and one in the gestures, with no API, visual or default change. Verified from the diff and the package source.
- The new test fails on main (784px instead of 448px), passes after the change, and also fails with only the panel's change. Consistent with the code on both sides; not run here, and CI has not run on this head.
- The BottomSheet suite (14 files, 616 tests) and the whole UI project pass, and typecheck, ESLint and Prettier are clean. Not run here; CI runs them before merge.
- No new test for the entrance flag or the motion callbacks: a discarded render's state update is discarded with it, the existing reactivation test covers the flag, and the old copy was already commit-time. Verified (
BottomSheetPanel.test.tsx:530; baseBottomSheetPanel.tsx:803-808). - History: the merges of main had no conflicts except one in
BottomSheetPanel.tsx, resolved to the keyed state; the next commit moved the resolver ontouseCommittedRef; a changeset-only commit narrows the second sentence; the latest merge of main brings an animator change the panel imports and leaves the change's own diff unchanged. Verified (commit history; the patch is byte-identical to the one reviewed before that merge, and the merged animator option is opt-in and unused by BottomSheet). - Browser interaction and accessibility specs pass in Chromium and WebKit, and the first run's PinchZoom and ChatVirtualizer failures pass on rerun. Not reproduced here.
- Scope: one defect restored, no hidden API, visual, default or interaction change, no internal context. Verified.
.changeset/bottom-sheet-snap-points-in-state.md: clear.packages/core/src/BottomSheet/BottomSheet.test.tsx: clear.packages/core/src/BottomSheet/BottomSheetPanel.tsx: clear.packages/core/src/BottomSheet/useSheetGestures.ts: clear.
|
/approve-spec 49a8b33 |
There was a problem hiding this comment.
Approved pending CI: CI has not run on this head yet; it runs once the pull request is marked ready for review (the ci:run label is already present).
The only change since the last review is a merge of main: the source changes are unchanged, and the test now shares the react import that main added. The new test fails on main (the sheet rests at 784px instead of 448px), fails with either half of the fix alone, and passes on this head. One optional follow-up remains: BaseTypeahead.tsx (lines 823-825) still cites BottomSheetPanel's layout-effect onMotionStartRef as its precedent, which this change removes.
Claims and files checked
- Changeset: the sheet keeps its snap points and its reactivated entrance in state and syncs the drag's stop resolver at commit. Verified (
BottomSheetPanel.tsx:797-809,:829-851;useSheetGestures.ts:715). - Changeset: a discarded render that changes
snapPointsno longer changes where a released drag rests. Verified: the new test fails on the base and passes here, and the other render-time values the release reads do not takesnapPoints(useSheetGestures.ts:631-632,:707-712). - The panel's snap-points ref, read by the stop resolver, and two writes of the entrance ref, read by the motion layout effect, were written during render; so was the gestures' resolver ref, read in a callback. Verified (base
BottomSheetPanel.tsx:798,:800,:828-829,:1017; baseuseSheetGestures.ts:717-718). - A discarded render left its values in those refs, so a released drag could rest at a stop the sheet never committed. Verified for snap points by the red-first run.
- The snap points are keyed state adjusted during render, so the resolver's identity changes only with the stops. Verified (
BottomSheetPanel.tsx:829-851). - The resolver comes from
useCommittedRef, written at commit before the re-anchor's layout effect reads it. Verified (useCommittedRef.ts:35-38;useSheetGestures.ts:715,:1015-1021). - The entrance flag is state adjusted as the panel's state changes, and the motion effect reads it. Verified (
BottomSheetPanel.tsx:797-809,:1023,:1091). - The three motion callbacks come from
useCommittedRefinstead of a layout effect's copy. Verified (BottomSheetPanel.tsx:788-790; the copy effect is gone). - The cited rules: no ref writes during render except initialization, state adjusted while rendering for previous-render information, latest-value refs through the shared hook, and no rendered value from a ref mutation. Verified against the current runtime architecture record.
- Six refs change in the panel, three of them the motion callbacks, and one in the gestures, with no API, visual or default change. Verified from the diff; the built API surfaces of Core and the themes compare with no changed row.
- The new test fails on main (784px instead of 448px) with the whole file run, and passes after the change. Verified: run here on both trees, with the other 159 tests in the file passing on the base.
- The existing snap-point and re-anchor tests still pass. Verified (the BottomSheet suite passes here).
- The new test also fails with only the panel's change. Verified (run here; it also fails with only the gestures' change).
- No new test for the entrance flag or the motion callbacks: a discarded render's state update is discarded with it, the existing reactivation test covers the flag, and the old copy was already commit-time. Verified (
BottomSheetPanel.test.tsx:530; baseBottomSheetPanel.tsx:803-808). - The BottomSheet suite (14 files, 617 tests) passes. Verified (run here).
- The whole UI project (1,007 files) passes. Not run here; CI runs it before merge.
- Core typecheck has 0 errors, and ESLint and Prettier are clean on the changed files. Verified (run here).
- History: the earlier merges of main, one conflict resolved to the keyed state, the move of the resolver onto the shared hook, and the changeset-only narrowing. Consistent with the commit history: main's snap-points ref and its lint disable are gone at this head, the resolver moves in the commit after that merge, and the narrowing commit touches only the changeset.
- History: the latest merge of main has no conflicts; the panel and gestures reach the click guard change, and the test shares the
reactimport both sides added. Verified for the panel, which reaches the click guard through the keyboard height module; the guard's new option is opt-in and unused by the sheet, and the import appears once. - Browser interaction and accessibility specs pass in Chromium and WebKit, and the first-run failures at the previous head passed on rerun. Not reproduced here.
- Scope: one defect restored, no hidden API, visual, default or interaction change, no internal context. Verified.
.changeset/bottom-sheet-snap-points-in-state.md: clear.packages/core/src/BottomSheet/BottomSheet.test.tsx: clear.packages/core/src/BottomSheet/BottomSheetPanel.tsx: clear.packages/core/src/BottomSheet/useSheetGestures.ts: clear.
|
/approve-spec 19e445b |
There was a problem hiding this comment.
Approved pending CI: CI has not run on this head yet; it runs once the pull request is marked ready for review (the ci:run label is already present).
The only change since the last review is a merge of main with no conflicts, and the pull request's own diff is unchanged. The new test still fails on main (the sheet rests at 784px instead of 448px), fails with either half of the fix alone, and passes on this head with the whole BottomSheet suite. One optional follow-up remains: Typeahead/BaseTypeahead.tsx (lines 823-825) still cites BottomSheetPanel's layout-effect onMotionStartRef as its precedent, which this change removes.
Claims and files checked
- Changeset: the sheet keeps its snap points and its reactivated entrance in state and syncs the drag's stop resolver at commit. Verified (
BottomSheetPanel.tsx:797-809,:829-851;useSheetGestures.ts:715). - Changeset: a discarded render that changes
snapPointsno longer changes where a released drag rests. Verified: the new test fails on the base and passes here, and the other render-time values the release reads do not takesnapPoints(useSheetGestures.ts:631-632,:707-712). - The panel's snap-points ref, read by the stop resolver, and two writes of the entrance ref, read by the motion layout effect, were written during render; so was the gestures' resolver ref, read in a callback. Verified (base
BottomSheetPanel.tsx:798,:800,:828-829,:1017; baseuseSheetGestures.ts:717-718). - A discarded render left its values in those refs, so a released drag could rest at a stop the sheet never committed. Verified for snap points by the red-first run.
- The snap points are keyed state adjusted during render, so the resolver's identity changes only with the stops. Verified (
BottomSheetPanel.tsx:829-851). - The resolver comes from
useCommittedRef, written at commit before the re-anchor's layout effect reads it. Verified (useCommittedRef.ts:35-38;useSheetGestures.ts:715,:1015-1021). - The entrance flag is state adjusted as the panel's state changes, and the motion effect reads it. Verified (
BottomSheetPanel.tsx:797-809,:1023,:1091). - The three motion callbacks come from
useCommittedRefinstead of a layout effect's copy. Verified (BottomSheetPanel.tsx:788-790; the copy effect is gone). - The cited rules: no ref writes during render except initialization, state adjusted while rendering for previous-render information, latest-value refs through the shared hook, and no rendered value from a ref mutation. Verified against the current runtime architecture record.
- Six refs change in the panel, three of them the motion callbacks, and one in the gestures, with no API, visual or default change. Verified from the diff; the built API surfaces of Core and the themes compare with no changed row.
- The new test fails on main (784px instead of 448px) with the whole file run, and passes after the change. Verified: run here on both trees, with the other 159 tests in the file passing on the base.
- The existing snap-point and re-anchor tests still pass. Verified (the BottomSheet suite passes here).
- The new test also fails with only the panel's change. Verified (run here; it also fails with only the gestures' change).
- No new test for the entrance flag or the motion callbacks: a discarded render's state update is discarded with it, the existing reactivation test covers the flag, and the old copy was already commit-time. Verified (
BottomSheetPanel.test.tsx:530; baseBottomSheetPanel.tsx:803-808). - The BottomSheet suite (14 files, 617 tests) passes. Verified (run here).
- The whole UI project passes. Not run here; CI runs it before merge.
- Core typecheck has 0 errors, and ESLint and Prettier are clean on the changed files. Verified (run here).
- History: the earlier merges of main, one conflict resolved to the keyed state, the move of the resolver onto the shared hook, and the changeset-only narrowing. Consistent with the commit history: main's snap-points ref and its lint disable are gone at this head, the resolver moves in the commit after that merge, and the narrowing commit touches only the changeset.
- History: the latest merge of main has no conflicts; the panel reaches four of main's changes (theme props, the shared resize observer, the theme rule generator and token references), and the change's own diff is unchanged. Verified: those four are the changed files the panel reaches through runtime imports, each gains an export or a padding-parsing fix the sheet's drag does not use, and the patch is byte-identical to the last reviewed one.
- Browser interaction and accessibility specs pass in Chromium and WebKit, and earlier first-run failures passed on rerun. Not reproduced here.
- Scope: one defect restored, no hidden API, visual, default or interaction change, no internal context. Verified.
.changeset/bottom-sheet-snap-points-in-state.md: clear.packages/core/src/BottomSheet/BottomSheet.test.tsx: clear.packages/core/src/BottomSheet/BottomSheetPanel.tsx: clear.packages/core/src/BottomSheet/useSheetGestures.ts: clear.






Render-time ref writes fixed in
core/BottomSheet/BottomSheetPanel.tsx:snapPointsRef, read by the stop resolver, and two writes ofreactivatedEntranceRef, read by the motion layout effect. Folded in, read in a callback:core/BottomSheet/useSheetGestures.tssnapHeightsRef. Red-first: yes, "rests at the committed stop when React discards a render that moves it" fails on main.User impact
People who drag a BottomSheet with snap points in an app that renders with transitions. BottomSheetPanel copied its snap points into a ref written during render, and the sheet's gestures copied the stop resolver the same way. A render React discards, as a suspended transition does, left its values there. A released drag could then rest at a stop the sheet never committed.
The panel also kept whether an entrance brings back a retained sheet in a ref written during render.
Problem and solution fit
A write during render runs for every render, including the ones React throws away. The drag resolves its stops on release, after the render that wrote them.
The snap points are now state, kept with their key and adjusted during render when the key changes. So the resolver's identity still changes only when the stops do. The gestures' resolver now comes from
useCommittedRef, which writes at commit, before the re-anchor's layout effect reads it. The entrance flag is state, adjusted as the panel's state changes, and the motion effect reads it. The three motion callbacks come fromuseCommittedReftoo, instead of a layout effect's copy.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
Six refs in
BottomSheetPanel.tsx, three of them the motion callbacks, and one inuseSheetGestures.ts. No API, visual or default changes.Evidence
Scope
Testing
All runs below are at this PR's head, 19e445b.
The new test opens a tall sheet with a stop at half the window. It renders a stop at a quarter of the window in a transition that suspends for good. React keeps the committed tree and never commits that render. It then drags the handle to the committed stop and releases it.
snapPointsRef(BottomSheetPanel.tsx)snapHeightsRef(useSheetGestures.ts)useCommittedRef, written before the re-anchor reads itreactivatedEntranceRef(BottomSheetPanel.tsx, two writes)useCommittedRef, no longer copied by a layout effectpnpm exec vitest run packages/core/src/BottomSheet --project ui: 14 files, 617 tests pass. On main's panel and gestures, with the whole file run, the new test fails and the other 159 pass.pnpm exec vitest run --project ui: 1,010 files, 25,130 tests pass.@astryxdesign/coretypecheck: 0 errors. ESLint and Prettier on the changed files: clean.History: main merged at 146df1e 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 2aa31a3 on Nov 12 has one conflict, in
BottomSheetPanel.tsx. Main's snap-points ref, from fix(Table): call the latest onSortChange from useTableSortableState #11349, gives way to this PR's keyed state, and its lint disable goes with it. The next commit moves the gestures' resolver ontouseCommittedRef.Browser specs at this head, on a Storybook built at it: BottomSheet interaction specs, Chromium 22 passed (1 skipped) and WebKit (CI-profile container) 12 passed (11 skipped). BottomSheet a11y specs, Chromium 92 passed; their
.browserspecs in the WebKit container, 55 passed (1 skipped).History: the merge of main 06b7e61 on Nov 12 has no conflicts. It brings main's changes to three files that
BottomSheetPanel.tsxreaches through its imports:motion/animator.ts,useMobileKeyboard.tsandkeyboardHeight.ts. The change's own diff is unchanged.History: a changeset-only commit narrows its second sentence to a discarded
snapPointschange, the case this PR fixes and tests.History: the merge of main badd698 on Nov 12 has no conflicts. It brings main's change to
motion/animator.ts, whichBottomSheetPanel.tsxreaches through its imports. The change's own diff is unchanged.At 1764d83, in a first run of these gates, four
BottomSheetPinchZoomcases failed: the story's dialog did not appear within 5 s. OneChatVirtualizercase inlabfailed too. All five passed in reruns there. With a delay injected into each test, both failures reproduce the same way on main badd698. The story's sheet opens in a median of 330 ms at that head and 327 ms on main, over 10 runs each. At this head, every gate passed on its first run.History: the merge of main a4595ef on Nov 12 has no conflicts.
BottomSheetPanel.tsxanduseSheetGestures.tsreach one of main's changes,utils/clickGuard.ts. The test file also reachesBottomSheet.tsxfrom fix(BottomSheet): sync its return target at commit #10918, and thereactimport both sides added appears once.History: the merge of main 723a112 on Nov 12 has no conflicts.
BottomSheetPanel.tsxreaches four of main's changes since a4595ef:utils/themeProps.ts, which it imports,utils/sharedResizeObserver.ts,theme/generateThemeRules.tsandtheme/tokenReferences.ts. The change's own diff is unchanged.