Skip to content

Commit 94eb29b

Browse files
authored
fix(useResizable): a drag saves its size once, when it ends, not on every move (#7782)
## User impact With `autoSaveId` (on `useResizable` or `SideNav`'s `resizable` config), a drag writes the saved size to `localStorage` on every `pointermove`. Browsers deliver each changed value to every other same-origin tab as a `storage` event, so one drag sends each of them dozens. In one app adopting Astryx, this save is the largest source of cross-tab storage bursts: about half of them, each a sibling tab receiving 50+ writes a second during a drag. ## Problem and solution fit 1. Why: persistence is an effect keyed on `size`, and a drag changes `size` on every move. 2. Harm: other tabs and `storage` listeners process every intermediate size. 3. Why it matters: the entry restores one size next session; nobody keeps an intermediate one. ## Expected behavior and authority - `component:Resizable` (current): FR3 gains the rule and the review check projects it: "storage holds the last settled size and receives the final size once when a drag ends, cancels, or unmounts." They need owner approval on this head. - `autoSaveId` ("remembers the pixel size across sessions") and `spec:AST-010` FR9: same key, `{size, isCollapsed}` shape and final value. FR5's text is unchanged. ## Smallest restoration - `useResizable.ts`: the persistence effect holds the size during a gesture and writes it once in the commit that applies the release, the first render to know the final size (a re-clamp, or a move the release came before). A region unmounting mid-gesture writes it on the way out. - `Resizable.spec.md`: the FR3 sentence, the review check projecting it (first clause narrowed to settled values; the table re-pads), and FR3's verification row. No API, default, key or format change. Keyboard steps, Enter, double-click, `resize()`, `collapse()` and `expand()` finish in one event and still write at once. Observable difference: a page closed mid-drag restores the pre-drag size. ## Evidence - Before: in Chromium, a 60-move drag of a Storybook handle sent a second tab 60 `storage` events; in jsdom, a 30-move drag wrote 30 times. - After: one event, on release, with main's final value (`{"size":519,"isCollapsed":false}`); jsdom: one write on `pointerup`, `pointercancel`, `lostpointercapture` or the handle's unmount, none mid-drag. - Unchanged path: three ArrowRight steps still write 210, 220, 230. - Tests: drag-end, unmount and keyboard cases in `ResizeHandle.test.tsx`; release, same-batch, unmount and re-clamp cases in `useResizable.test.ts`, each asserting one final write. An older test now ends its gesture before reading storage. ## Scope - [x] One defect is restored. - [x] Separable contradictory or unsettled tagalongs were removed or split. - [x] No new public API, visual representation, default, or interaction model is hidden under the bug-fix label. - [x] Public text and artifacts contain no internal Meta context. ## Writing rubric results - R1 narration: none. - R2 research: none. - R3 evidence: FR3's verification cell names tests, not a pull request. - R4 rejected alternatives: none. - R5 change references: none. - R6 open questions: none. ## Testing Local gates at `1a138a9` (one commit on main `dade717c5`; the patch is byte-identical to the previous head's): - Red: with main's `useResizable.ts`, eight new cases fail, including the three "saves the size once, when a drag ends on …" cases (`expected [ …(30) ] to have a length of +0 but got 30`); with an earlier version that wrote from the end and cancel handlers, the same-batch, re-clamp and unmount cases fail. Green: the Resizable and SideNav suites pass, 451/452; the one failure is `utils.test.ts`, which also times out alone on main `dade717c5` (the open #8471 fixes it). - `pnpm build`, `pnpm -F @astryxdesign/core typecheck`, `pnpm check:knowledge`, `pnpm lint` (`check:repo` and `eslint .`: 0 errors, none in changed files), `prettier --check`, `check:changesets` and changeset coverage pass. - Chromium 149, Storybook dev (`Core/Hooks/useResizable`, Structured Percent Sizing), checking the served `useResizable.ts` on each run: `storage` events in a second tab during a 60-move drag: main 60; this head 0, then 1 on release. Both end at `{"size":519,"isCollapsed":false}`. - Full suites, on the same patch over main `a587813542`: `pnpm test:ui` 17,066/17,070 and `pnpm test:node` 14,672/14,681, under heavy machine load. None of the failing files reads a file this pull request changes, and each either passed alone or failed the same way alone on that main.
1 parent 134d006 commit 94eb29b

5 files changed

Lines changed: 269 additions & 20 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[perf] `useResizable` with `autoSaveId` (and `SideNav` with `resizable={{autoSaveId}}`) now saves a dragged size to `localStorage` once, when the drag ends, instead of on every pointer move. Every write reached each other open tab of the site as a `storage` event, so one drag sent dozens of them. The storage key, the stored format and the size saved at the end are unchanged, and keyboard steps, `resize()`, `collapse()` and `expand()` still save at once.
6+
7+
@vjeux

0 commit comments

Comments
 (0)