Repository navigation
fix(BottomSheet): sync its return target at commit - #10918
Conversation
The sheet kept its finalFocusRef and its stack view in refs written while it rendered. A render React discards, as a suspended transition does, left its values there. A sheet the page removed after a discarded render with another finalFocusRef then returned focus to that render's target. The return target now syncs in an insertion effect, ahead of the layout effects where the stack can close the sheet. The stack view is no longer copied during render: the registry's onView already writes it with each view it reports.
|
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 |
|---|---|---|---|
| BottomSheetSwitcher | 18.7 kB (0) · 3.4 kB CSS (0) | — | ✗ · ✓ · — |
| BottomSheet | 69.9 kB (−5 B) · 7.7 kB CSS (0) | — | ✗ · ✓ · — |
| richtext/RichTextEditorToolbar | 284.9 kB (+19 B) · 454 B CSS (0) | — | — · — · — |
22 more components
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| Markdown | 193.6 kB (+7 B) · 21.0 kB CSS (0) | — | — · — · — |
| Table | 130.6 kB (+5 B) · 18.7 kB CSS (0) | — | — · — · — |
| lab/CommentComposer | 157.0 kB (+3 B) · 1.9 kB CSS (0) | — | — · — · — |
| DropdownMenu | 102.6 kB (+1 B) · 17.9 kB CSS (0) | — | — · — · — |
| Tokenizer | 102.2 kB (+1 B) · 19.5 kB CSS (0) | — | — · — · — |
| TableCell | 114.6 kB (0) · 18.2 kB CSS (0) | — | — · — · — |
| MoreMenu | 102.8 kB (−1 B) · 17.9 kB CSS (0) | — | — · — · — |
| PowerSearch | 301.0 kB (−1 B) · 24.7 kB CSS (0) | — | — · — · — |
| lab/TourStep | 102.3 kB (−2 B) · 590 B CSS (0) | — | — · — · — |
| lab/ChatReactionBar | 112.5 kB (−3 B) · 1.1 kB CSS (0) | — | — · — · — |
| lab/Comments | 360.4 kB (−4 B) · 2.5 kB CSS (0) | — | — · — · — |
| lab/CommentThread | 353.7 kB (−7 B) · 2.4 kB CSS (0) | — | — · — · — |
| ContextMenu | 113.4 kB (−9 B) · 17.8 kB CSS (0) | — | — · — · — |
| Pagination | 115.7 kB (−11 B) · 18.2 kB CSS (0) | — | — · — · — |
| TableHeaderCell | 114.2 kB (−14 B) · 18.0 kB CSS (0) | — | — · — · — |
| lab/ChatEmojiPicker | 111.3 kB (−15 B) · 773 B CSS (0) | — | — · — · — |
| Popover | 96.0 kB (−16 B) · 14.6 kB CSS (0) | — | — · — · — |
| DateInput | 194.5 kB (−17 B) · 17.4 kB CSS (0) | — | — · — · — |
| MultiSelector | 99.8 kB (−17 B) · 17.2 kB CSS (0) | — | — · — · — |
| Selector | 105.5 kB (−18 B) · 17.8 kB CSS (0) | — | — · — · — |
| DateTimeInput | 217.0 kB (−25 B) · 19.1 kB CSS (0) | — | — · — · — |
| TimeInput | 168.5 kB (−44 B) · 16.4 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.40 MB packed (+227 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 return-target write into an insertion effect keeps a discarded transition render out of it, so a sheet removed after such a render returns focus to its committed finalFocusRef; the new test fails without the change and passes with it, and a Chromium check shows the same.
Next step: this is a draft from a fork, so a maintainer adds the ci:run label, and marking the pull request ready for review then starts CI.
- Optional: the new test sits in the
hasScrim={false} (non-modal)block but renders a modal sheet; move it to the "BottomSheet removed while open" suite inBottomSheetCloseFocus.test.tsx, or addhasScrim={false}.
[Automated review]
| } | ||
| }); | ||
|
|
||
| it('returns focus to the committed finalFocusRef when it unmounts after React discards a render with another', async () => { |
There was a problem hiding this comment.
Non-blocking: this test sits in describe('hasScrim={false} (non-modal)'), but the sheet below passes no hasScrim={false}, so it runs the modal path while a failure reports a non-modal case. Move it to the "BottomSheet removed while open" suite in BottomSheetCloseFocus.test.tsx, or add hasScrim={false}; with that prop it still fails without the fix and passes with it.
| }, | ||
| [], | ||
| ); | ||
| // The stack's view for the handlers. The registry's `onView` writes it with |
There was a problem hiding this comment.
Non-blocking (INV29): "The stack's view for the handlers." restates the ref's name. Keep only the invariant, for example:
// Only the registry's `onView` writes it, in the same call that sets the state.|
/approve-spec fd28a7c |
There was a problem hiding this comment.
Approved pending CI: CI has not run on this head yet.
Moving the return-target write into an insertion effect keeps a discarded transition render out of it, so a sheet removed after such a render returns focus to its committed finalFocusRef. The new test fails without the change and passes with it, for modal and non-modal sheets, and a Chromium check shows the same.
Next step: the ci:run label is already on this pull request, so CI runs once it is marked ready for review.
- Optional: the two earlier notes still apply: the new test sits in the
hasScrim={false} (non-modal)block but renders a modal sheet, and the comment abovestackViewRefrestates its name.
The sheet copied the committed finalFocusRef into a ref in its own insertion effect. The shared internal hook makes the same write, so the sheet calls it. The stack's callback and the removal repair read the target through one function, so focus returns where it did.
|
/approve-spec fcdf454 |
There was a problem hiding this comment.
Approved pending CI: CI has not finished on this head yet.
Reading the return target through useCommittedRef keeps a discarded transition render out of it, so a sheet removed after such a render returns focus to its committed finalFocusRef, as the sheet's focus-return rule requires. CI is running on this head now, and merging waits for it.
- Optional: the new test sits in the
hasScrim={false} (non-modal)block but renders a modal sheet; move it to the "BottomSheet removed while open" suite inBottomSheetCloseFocus.test.tsx, or addhasScrim={false}. - Optional: three comments in
BottomSheet.tsxrestate names or misplace where the target is read; the inline suggestions give shorter wording.
Claims and files checked
- Changeset: the sheet writes its focus return target at commit and no longer copies its stack view during render: verified (
BottomSheet.tsx:464,:567-569). - Changeset and description: a sheet removed after a discarded render returns focus to its committed
finalFocusRef: verified (the commit-time write atBottomSheet.tsx:464and the test sequence atBottomSheet.test.tsx:980). - The new test fails on the base branch and passes at this head: verified from the code (the base writes the discarded target during render; the head writes only at commit).
- The registry's callback and the removal repair read the target through one function: verified (
BottomSheet.tsx:622-624,:649,:687). - The stack view changes only in the registry's
onView, so the render-time copy only repeated that write: verified (BottomSheet.tsx:651-652). - No API, visual or default change: verified (only the unexported standalone sheet changes).
- The governing rules (no ref writes during render, latest-value refs through the shared hook, no rendered value from a ref): verified against the current runtime architecture record.
- Existing tests, typecheck, lint and formatting pass: consistent with the code (types and hook dependencies line up); CI confirms.
- Both merges of the base branch are conflict-free, and the last brings the shared hook that the next commit adopts: verified from the history.
.changeset/bottom-sheet-return-target-at-commit.md: clear.packages/core/src/BottomSheet/BottomSheet.test.tsx: test placement note.packages/core/src/BottomSheet/BottomSheet.tsx: comment wording notes.
| // The committed `finalFocusRef`. The stack reads it when it closes the | ||
| // sheet, which can happen in a layout effect. |
There was a problem hiding this comment.
Non-blocking (INV29): the registry reads this target in its passive-effect seal (bottomSheetStack.ts:429), not in a layout effect; the layout-effect read is this sheet's own removal cleanup (line 687). The first sentence restates the hook's name. Keep only the reason, for example:
// A render React discards must not change where focus returns.| dialog == null | ||
| ? null | ||
| : prepareFocusRepairOnRemoval(dialog, {keepRestingFocus: true}); | ||
| // Where focus returns when the sheet leaves, read when it leaves. |
There was a problem hiding this comment.
Non-blocking (INV29): "Where focus returns when the sheet leaves" restates getReturnTarget. Keep the constraint, for example:
// Read it when the sheet leaves. This effect does not run again for a new `finalFocusRef`.|
/approve-spec 980236a |
There was a problem hiding this comment.
Approved pending CI: CI skipped every job on this head because the pull request is a draft, and it runs once the pull request is marked ready for review.
Reading the return target through useCommittedRef keeps a discarded transition render out of it, so a sheet removed after such a render returns focus to its committed finalFocusRef, as the sheet's focus-return rule requires.
- Optional: the new test sits in the
hasScrim={false} (non-modal)block but renders a modal sheet; move it to the "BottomSheet removed while open" suite inBottomSheetCloseFocus.test.tsx, or addhasScrim={false}. - Optional: three comments in
BottomSheet.tsx(lines 462, 567 and 622) restate names or misplace where the target is read; the open inline suggestions give shorter wording.
Claims and files checked
- Changeset: the sheet writes its focus return target at commit and no longer copies its stack view during render: verified (
BottomSheet.tsx:464,:567-569). - Changeset and description: a sheet removed after a discarded render returns focus to its committed
finalFocusRef: verified (the shared hook's commit-time write atBottomSheet.tsx:464, and the test sequence atBottomSheet.test.tsx:980). - Both refs were written during render and are read only in callbacks and effects: verified (base
BottomSheet.tsx:462,:566; head reads at:581,:594,:623-624,:643,:759,:780,:898-899). - The new test fails on the base branch and passes at this head: verified from the code (the base writes the discarded target during render; the head writes only at commit); not run here.
- The target is written at commit, before every layout effect: verified (
useCommittedRef.ts:35-38writes in an insertion effect). - The registry's callback and the removal repair read the target through one function: verified (
BottomSheet.tsx:623-624,:649,:687). - The stack view changes only in the registry's
onView, so the render-time copy only repeated that write: verified (BottomSheet.tsx:651-652). - The governing rules (no ref writes during render, latest-value refs through the shared hook, no rendered value from a ref): verified against the current runtime architecture record.
- No API, visual or default change: verified from the code (only the unexported standalone sheet's body changes, and no render reads either ref).
- Existing tests, typecheck, lint, formatting and browser specs pass: consistent with the code (types and hook dependencies line up); not rerun here, and CI has not run on this head.
- Each merge of the base branch is conflict-free, the second brings the shared hook, and the last brings changes to four files the sheet imports while the change's own diff stays the same: verified from the history.
- One defect, no tagalong, no hidden API or interaction change, no internal context: verified.
.changeset/bottom-sheet-return-target-at-commit.md: clear.packages/core/src/BottomSheet/BottomSheet.test.tsx: test placement note.packages/core/src/BottomSheet/BottomSheet.tsx: comment wording notes.
|
/approve-spec e8ac261 |
There was a problem hiding this comment.
Approved pending CI: CI skipped every job on this head because the pull request is a draft, and it runs once the pull request is marked ready for review.
Reading the return target through useCommittedRef keeps a discarded transition render out of it, so a sheet removed after such a render returns focus to its committed finalFocusRef, as the sheet's focus-return rule requires.
- Optional: the new test sits in the
hasScrim={false} (non-modal)block but renders a modal sheet; move it to the "BottomSheet removed while open" suite inBottomSheetCloseFocus.test.tsx, or addhasScrim={false}. - Optional: three comments in
BottomSheet.tsx(lines 462, 567 and 622) restate names or misplace where the target is read; the open inline suggestions give shorter wording.
Claims and files checked
- Changeset: the sheet writes its focus return target at commit and no longer copies its stack view during render: verified (
BottomSheet.tsx:464,:567-569). - Changeset and description: a sheet removed after a discarded render returns focus to its committed
finalFocusRef: verified (the shared hook's commit-time write atBottomSheet.tsx:464, and the test sequence atBottomSheet.test.tsx:980). - Both refs were written during render and are read only in callbacks and effects: verified (base
BottomSheet.tsx:461-462,:566; head reads at:581,:594,:623-624,:643,:759,:780,:898-899). - The new test fails on the base branch and passes at this head: verified from the code (the base writes the discarded target during render; the head writes only at commit); not run here.
- The target is written at commit, before every layout effect: verified (
useCommittedRef.ts:35-38writes in an insertion effect). - The stack reads the target when it closes or removes the sheet, in a layout-effect cleanup or later: verified (the removal cleanup at
BottomSheet.tsx:687; the registry's seal atbottomSheetStack.ts:429runs from a passive effect or a microtask). - The registry's callback and the removal repair read the target through one function: verified (
BottomSheet.tsx:623-624,:649,:687). - The stack view changes only in the registry's
onView, so the render-time copy only repeated that write: verified (BottomSheet.tsx:651-652). - The governing rules (no ref writes during render, latest-value refs through the shared hook, no rendered value from a ref): verified against the current runtime architecture record.
- No API, visual or default change: verified from the code (only the unexported standalone sheet's body changes, and no render reads either ref).
- Existing tests, typecheck, lint, formatting and browser specs pass: consistent with the code; not rerun here, and CI has not run on this head.
- Each merge of the base branch is conflict-free, the second brings the shared hook, the third brings changes to four files the sheet reaches, the last brings the animator change, and the change's own diff stays the same: verified from the history.
- One defect, no tagalong, no hidden API or interaction change, no internal context: verified.
.changeset/bottom-sheet-return-target-at-commit.md: clear.packages/core/src/BottomSheet/BottomSheet.test.tsx: test placement note.packages/core/src/BottomSheet/BottomSheet.tsx: comment wording notes.






Render-time ref writes fixed, each read in a callback:
finalFocusRefRefandstackViewRefincore/BottomSheet/BottomSheet.tsx. Red-first: yes, "returns focus to the committed finalFocusRef when it unmounts after React discards a render with another" fails on main.User impact
People using a BottomSheet with a
finalFocusRef, in an app that renders with transitions. The sheet kept itsfinalFocusRefand its stack view in refs written while it rendered. A render React discards, as a suspended transition does, left its values there. A sheet the page removed after a discarded render with anotherfinalFocusRefreturned focus to that render's target.Problem and solution fit
A write during render runs for every render, including the ones React throws away. The stack reads the return target when it closes or removes the sheet, which can happen in a layout effect or an unmount cleanup.
The return target now comes from
useCommittedRef, Core's shared hook for latest-value refs. It writes at commit, before every layout effect, where the stack can close the sheet. The stack's callback and the removal repair read it through one function when they run. The stack view is no longer copied during render. The registry'sonViewalready writes it with every view it reports, together with the state, so the copy only ever repeated that write.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
Two refs in
BottomSheet.tsx. No API, visual or default changes.Evidence
Scope
Testing
All runs below are at this PR's head, e8ac261.
The test renders an open sheet with focus inside it. A transition renders it with another
finalFocusRefwhile a sibling suspends for good, so React never commits that render. The page then removes the sheet, and its removal returns focus.finalFocusRefRefuseCommittedRefstackViewRefonViewpnpm exec vitest run packages/core/src/BottomSheet packages/core/src/Tokenizer packages/core/src/DropdownMenu packages/core/src/Toast --project ui: 41 files, 1431 tests pass.pnpm exec vitest run --project ui: 1,002 files, 24,751 tests pass.BottomSheet.test.tsxrun whole against main's sheet: the new test fails, and the other 158 pass.@astryxdesign/coretypecheck: 0 errors. ESLint and Prettier on the changed files: clean.useCommittedRef. The next commit moves the return target onto it in place of the sheet's own insertion effect..browserspecs in the WebKit container, 55 passed (1 skipped).BottomSheet.tsxreaches through its imports:BottomSheetPanel.tsx,motion/animator.ts,useMobileKeyboard.tsandkeyboardHeight.ts. The change's own diff is unchanged.motion/animator.ts, whichBottomSheet.tsxreaches through its imports. The change's own diff is unchanged.