Repository navigation
fix(Table): call the latest onSortChange from useTableSortableState - #11349
Conversation
…lues directly in render
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
|
/approve-spec 4451825 |
PR Analysis Report🔎 Preview ·
|
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| BottomSheet | 69.4 kB (+6 B) · 7.7 kB CSS (0) | — | ✗ · ✓ · — |
| BottomSheetSwitcher | 18.6 kB (0) · 3.4 kB CSS (0) | — | ✗ · ✓ · — |
| TableBody | 3.5 kB (0) · 3.3 kB CSS (0) | — | ✓ · ✓ · ✗ |
27 more components
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| TableFooter | 3.5 kB (0) · 3.3 kB CSS (0) | — | ✓ · ✓ · ✗ |
| TableHeader | 3.5 kB (0) · 3.3 kB CSS (0) | — | ✓ · ✓ · ✗ |
| TableRow | 7.1 kB (0) · 4.0 kB CSS (0) | — | ✓ · ✓ · ✗ |
| PowerSearch | 299.3 kB (+3 B) · 24.7 kB CSS (0) | — | — · — · — |
| DateTimeInput | 215.4 kB (+2 B) · 18.7 kB CSS (0) | — | — · — · — |
| DateInput | 192.8 kB (+1 B) · 17.0 kB CSS (0) | — | — · — · — |
| TableCell | 114.5 kB (+1 B) · 18.0 kB CSS (0) | — | ✓ · ✓ · ✓ |
| Tokenizer | 102.0 kB (+1 B) · 19.1 kB CSS (0) | — | — · — · — |
| lab/Comments | 358.8 kB (+1 B) · 2.5 kB CSS (0) | — | — · — · — |
| lab/CommentThread | 352.1 kB (+1 B) · 2.4 kB CSS (0) | — | — · — · — |
| Markdown | 193.4 kB (0) · 20.8 kB CSS (0) | — | — · — · — |
| MultiSelector | 99.7 kB (0) · 16.9 kB CSS (0) | — | — · — · — |
| Pagination | 115.5 kB (0) · 17.8 kB CSS (0) | — | — · — · — |
| Selector | 105.3 kB (0) · 17.4 kB CSS (0) | — | — · — · — |
| Table | 130.4 kB (0) · 18.5 kB CSS (0) | — | ✓ · ✓ · — |
| TableHeaderCell | 114.0 kB (0) · 17.7 kB CSS (0) | — | ✓ · ✓ · ✓ |
| TableSelectionToolbar | 73.7 kB (0) · 13.2 kB CSS (0) | — | ✓ · ✓ · ✓ |
| lab/ChatEmojiPicker | 110.7 kB (0) · 773 B CSS (0) | — | — · — · — |
| lab/ChatReactionBar | 111.8 kB (0) · 1.1 kB CSS (0) | — | — · — · — |
| lab/CommentComposer | 156.4 kB (0) · 1.9 kB CSS (0) | — | — · — · — |
| lab/TourStep | 101.7 kB (0) · 590 B CSS (0) | — | — · — · — |
| richtext/RichTextEditorToolbar | 284.4 kB (0) · 454 B CSS (0) | — | — · — · — |
| MoreMenu | 102.5 kB (−1 B) · 17.6 kB CSS (0) | — | — · — · — |
| Popover | 95.4 kB (−1 B) · 14.2 kB CSS (0) | — | — · — · — |
| ContextMenu | 113.2 kB (−2 B) · 17.5 kB CSS (0) | — | — · — · — |
| DropdownMenu | 102.3 kB (−3 B) · 17.6 kB CSS (0) | — | — · — · — |
| TimeInput | 167.5 kB (−6 B) · 16.0 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.37 MB packed (+269 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. CI passed on this head, including the new regression test.
The stable handleSortChange wrapper makes every sort activation call the parent's current onSortChange, and the new test pins the case where the handler changes while the sort stays the same. The comparators and snapPoints reads now follow the runtime rule that a latest-value ref is read only in callbacks, never during render or in useMemo.
- Optional: the reworded sentence at
BottomSheetPanel.tsx:824-826is 28 words; the earlier inline suggestion splits it. - Follow-up, not for this pull request: once the committed-ref hook lands (#11352),
onSortChangeRefand the other two refs here should be written through it instead of during render.
Claims and files checked
- Sorting through the sort-state hook calls the caller's latest sort handler: verified (
useTableSortableState.tsx:294-297,:317). - Before, a sort kept the handler from the last sort change, so a new handler passed without a sort change was skipped: verified against the base memo and the plugin's click path (
useTableSortable.tsx:251-287). - The config keeps one stable handler and does not change for an inline callback: verified (
useTableSortableState.tsx:321). - The comparators memo and the bottom sheet's ignored-points warning read their values directly and change no behavior: verified (
useTableSortableState.tsx:301,BottomSheetPanel.tsx:834). - Comparator identity still does not re-sort, and a comment on the dependency list says so: verified (
useTableSortableState.tsx:302-303; test atuseTableSortableState.test.tsx:320-351). - The bottom sheet memo stays keyed on the snap points and its resolver reads the ref at call time: verified (
BottomSheetPanel.tsx:839,:846). - The sort header's own ref read is left for a Table API decision: verified (
useTableSortable.tsx:227). - No new public API: verified from the source diff.
- The new test fails before the change and passes after it: it passes in CI on this head; the failure before the change is verified by reading the code.
- The stated suite, lint and typecheck results: CI's test, lint and typecheck jobs passed on this head; the local pre-review run is not verified here.
- Files:
.changeset/table-sort-latest-handler.mdclear;packages/core/src/BottomSheet/BottomSheetPanel.tsxclear, with the optional comment suggestion;packages/core/src/Table/plugins/sortable/useTableSortableState.test.tsxclear;packages/core/src/Table/plugins/sortable/useTableSortableState.tsxclear.
| // changed, so it must not churn on a re-render the drag caused. The resolver | ||
| // reads the points through a ref, so it resolves them at call time — | ||
| // against whatever the viewport is then, not what it was at memo time. |
There was a problem hiding this comment.
Optional: the reworded sentence runs 28 words, over the 25-word limit for a description in the source-comment rule, and covers two topics. For example:
// changed, so it must not churn on a re-render the drag caused. The resolver
// reads the points through a ref when it runs. It resolves them against the
// viewport at that time, not at memo time.





User impact
A table that uses
useTableSortableStatewith a controlledonSortChangecalled an old handler. The header kept the handler from the last sort change. A parent that passed a new handler while the sort stayed the same, for example after a filter or page change, had its old handler called when the user sorted, and that handler acted on out-of-date state.Problem and solution fit
onSortChangeRef.currentwhile rendering, in a memo keyed on the sort state. The copy is only as new as the last sort change.onSortChangewhen the user sorts. In the same way, two other render-time reads of a latest-value ref now read the value directly (the comparators memo, and BottomSheetPanel's ignored snap points). Neither of those two changes behavior today; both remove a render read.Expected behavior and authority
architecture:react-component-runtime: render stays pure, and a mutable ref is not the source of rendered output (INV4). The documenteduseTableSortableStatecontract is that the table calls the consumer'sonSortChange, which means the current one.Smallest restoration
useTableSortableState:onSortChangein the config is a stableuseCallbackthat calls the latest handler. The config still does not change when a parent passes an inline callback.useTableSortableState: the sorted-data memo readscomparatorsdirectly. Comparator identity still does not re-sort, because callers often pass an inline object. A comment on the dependency list says so.BottomSheetPanel: the ignored-points message readssnapPointsdirectly. The memo stays keyed on the snap points' identity, and the resolver still reads its ref at call time.useTableSortable:227. The plugin's stable-identity contract needs an owner decision. The plugin is documented and tested as "referentially stable across renders", so header rendering can see the current sort only through a ref read during render.New public API: none.
Evidence
onSortChange={first}, re-renders withsecondand the same sort, then presses a header. Onmain,firstwas called (red).secondis called andfirstis not.Scope
Components: Table, BottomSheet
Testing
vitest run packages/core/src/Table/plugins/sortable packages/core/src/BottomSheet.pnpm check:changesets.no-comment-provenance.baseline.mjs --check.pnpm review:pre: 0 findings, merges cleanly.