Repository navigation
fix(useResizable): a drag saves its size once, when it ends, not on every move - #7782
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report
Component Size
Sizes are gzip. Import counts the JavaScript the import loads eagerly; CSS counts the package stylesheet rules referenced by the modules it can load from its own package, lazily loaded ones included. Bundle Size SummaryGzip figures measure each package's entry file, not the code an import pulls in.
Published Package Size
10 other published packages are unchanged. Download is the gzip tarball npm fetches; unpacked is what lands in Accessibility AuditStatus: Accessibility did not run on this pull request; add Generated by PR Enrichment workflow | View full report |
There was a problem hiding this comment.
The change does what it describes: a drag now saves its size once, on release or cancel, with the same key, format and final value, and the new drag-end tests fail on main and pass on this branch. Approval waits on one maintainer decision. spec:AST-010 FR5 requires the persisted expanded value to describe the same geometry as state, paint and ARIA, and a maintainer needs to say whether that applies while a drag is still in flight, because this branch keeps the pre-drag entry until the gesture ends, so a page closed mid-drag restores the pre-drag size. If a maintainer confirms FR5 means settled geometry, or amends it to say so, you need to do nothing else.
[Automated review]
|
No inline comments, so I'm answering the one finding here. No code change. The open question is whether
Proposed reading, pending owner review: the persisted expanded value FR5 governs is the settled one. Mid-gesture, storage keeps the last settled entry, and the end of the gesture writes the resolved size. |
2e9d196 to
0f7c795
Compare
There was a problem hiding this comment.
The change does what it describes: a drag now saves its size once, on release or cancel, with the same key, format and final value, and the new drag-end tests fail on main and pass on this branch. Approval waits on one maintainer decision: spec:AST-010 FR5 requires the persisted expanded value to describe the same geometry as state, paint and ARIA, and the AST-010 owner needs to say whether that applies while a drag is still in flight, because this branch keeps the pre-drag entry until release, so a page reloaded mid-drag comes back at the pre-drag size. Your comment proposes the settled reading pending owner review; if the owner confirms it, or amends FR5 to say so, nothing else needs to change.
[Automated review]
0f7c795 to
aa26c91
Compare
|
This head records the settled-size reading in |
There was a problem hiding this comment.
The code does what the title says: a drag now saves its size once, when it ends or is cancelled, with the same key, format and final value, and the new drag-end tests fail on main and pass on this branch. Approval waits on an engineering owner's decision on the settled-size sentence this head adds to component:Resizable's Review checks, and on whether spec:AST-010 FR5 lets storage lag a drag in flight; an engineering owner records it by commenting /approve-spec <full head SHA> on this pull request, and the author may do so if they are an engineering owner. Two more changes are needed:
- Put the settled-storage rule in the record's body (FR3 or FR5) with a Verification-map row for the new tests and let the Review check project it, since Review checks may not state policy the body lacks and the cell's first clause still rejects storage that disagrees with state.
- Flush the pending write in
releaseGestureBasis, whichonResizeEnd,onResizeCancelandResizeHandle's unmount cleanup already reach, instead of in an Effect after a forced render, and drop the extra unmount Effect.
[Automated review]
| | End-user impact | People drag or use the keyboard to resize a panel, collapse and restore it, and have the size remembered, with the divider moving the way the page reads. | | ||
| | Builder impact | None; the record describes shipped behavior. | | ||
| | Compatibility/readiness | Released behavior recorded as current; no API, default, or output changes. Implementation gaps are listed under Current-state impact. | | ||
| | Review checks | Reject a Handle that loses its splitter role, values, or keys, arrows that move against the reading direction, a percentage default that rescales, or state, paint, storage, and ARIA that disagree; storage holds the last settled size and receives the final size once when a drag ends, cancels, or unmounts. | |
There was a problem hiding this comment.
This clause states a rule the record's body does not hold: Intent, FR3 and FR5 say nothing about when persistence writes, and architecture:knowledge-contracts says Review checks project settled requirements from the body and do not invent policy. Put the rule in FR3 or FR5 with a Verification-map row naming the new tests, and narrow the cell's first clause to settled values, since "state, paint, storage, and ARIA that disagree" still rejects the mid-drag lag this clause requires.
There was a problem hiding this comment.
Done in 807e791: FR3 now states the rule ("With autoSaveId, storage holds the last settled size and receives the final size once when a drag ends, cancels, or unmounts."), this cell projects it with its first clause narrowed to "settled state, paint, storage, and ARIA that disagree", and FR3's verification row names the new tests.
| useEffect( | ||
| () => () => { | ||
| const pending = pendingWriteRef.current; | ||
| if (pending != null) { | ||
| persistState(pending.key, pending.state); | ||
| } | ||
| }, | ||
| [], | ||
| ); |
There was a problem hiding this comment.
This Effect exists because the release write rides the render setGestureTick forces, which never commits when the region unmounts. Flushing pendingWriteRef inside releaseGestureBasis (reached by onResizeEnd, onResizeCancel, and ResizeHandle on pointerup, pointercancel, lost capture and unmount) keeps the write in the handler architecture:react-component-runtime INV2 asks for and makes this Effect unnecessary; the persistence Effect can read gestureBasisRef instead of depending on isGestureActive.
There was a problem hiding this comment.
Done in 807e791: releaseGestureBasis writes the pending size itself, so _onResizeEnd, _onResizeCancel and ResizeHandle's unmount cleanup all write from the handler. The unmount Effect is gone, and the persistence Effect reads gestureBasisRef. Two new tests read storage inside the end and cancel handlers' batch, before any render; they fail on the previous head. If a release lands between a move's commit and its passive effect, that effect still writes the final size after the handler's write.
aa26c91 to
807e791
Compare
|
/approve-spec 807e791 |
There was a problem hiding this comment.
A drag now saves its size once, when it ends, with the same key, format and final value, and an engineering owner has approved the FR3 storage-timing rule at this head; one fix is needed before this can merge. The end-of-drag write in releaseGestureBasis stores the last committed size before the release render, so a drag whose container resized mid-drag writes 180 and then 150, and a release that lands before the last move renders writes 280 and then 300, which contradicts FR3's "holds the last settled size and receives the final size once" and the changeset's "once". Let the commit that applies the release perform the end write (with a comment on why it runs after that render), keep a flush for a region that unmounts mid-gesture, and have the two handler tests read storage after the release render.
[Automated review]
| const pending = pendingWriteRef.current; | ||
| pendingWriteRef.current = null; | ||
| if (pending != null) { | ||
| persistState(pending.key, pending.state); |
There was a problem hiding this comment.
This writes the value the persistence Effect parked after the last committed move, before the render that applies the released basis. With a percentage bound whose container resized mid-drag, the release render re-clamps and writes again (180, then 150); when the release lands before the last move has rendered, 280 is written before 300. FR3 at this head says storage holds the last settled size and receives the final size once. Letting the commit that applies the release perform the end write (INV2 forbids deferral only when the handler can perform it, and no handler sees the re-clamped size), with a flush for a region that unmounts first, keeps that sentence true.
There was a problem hiding this comment.
Fixed in b124f38. The end write is back in the commit that applies the release, with a comment on why: that render is the first to know the final size, after a re-clamp or a move the release came before. A region that unmounts mid-gesture flushes on the way out, and the handler writes nothing. This replaces the handler write I made for the earlier thread.
New tests in useResizable.test.ts fail on the previous head:
- same-batch release: 280 then 300;
- container shrank mid-drag: 280 then 200;
- hook-only unmount: nothing written.
The two handler tests now read storage after the release render. FR3's verification row names the tests and adds "stale" to the failure it catches.
807e791 to
b124f38
Compare
|
/approve-spec b124f38 |
There was a problem hiding this comment.
Recommending approval: a drag now saves its size once, when it ends, is cancelled or unmounts, with the same storage key, format and final value, and the new tests (including the same-batch release and the mid-drag container resize) fail on main and pass here. The storage-timing rule added to component:Resizable FR3 is approved by an engineering owner at this head. One optional follow-up: a clause in the changeset noting that a page closed mid-drag now restores the pre-drag size would tell consumers about the only observable trade-off.
[Automated review]
…very move With autoSaveId, the persistence effect ran on every size change, and a pointer drag changes the size on every pointermove, so one drag wrote localStorage dozens of times. Each changed value reaches every other open document of the origin as a `storage` event. The effect now holds the size while a gesture is in flight and writes it once in the commit that applies the release, the first render to know the final size: a basis that changed mid-gesture re-clamps only at the release, and a move the release arrived before renders together with it. A region that unmounts mid-gesture writes the size the gesture reached on the way out. Keyboard steps, resize(), collapse() and expand() run their whole gesture in one event and still write at once. The key, the stored shape and the final value are unchanged. Resizable's FR3 records the timing and its review check projects it: storage holds the last settled size and receives the final size once when a drag ends, cancels, or unmounts.
b124f38 to
1a138a9
Compare
|
/approve-spec 1a138a9 |
There was a problem hiding this comment.
Recommending approval: a drag now saves its size once, when it ends, is cancelled or unmounts, with the same storage key, format and final value, and the new storage-timing tests fail with main's hook and pass here. The storage-timing rule added to component:Resizable FR3 is approved by an engineering owner at this head. Optional: a clause in the changeset noting that a page closed mid-drag now restores the pre-drag size would tell consumers about the one observable trade-off.
[Automated review]
User impact
With
autoSaveId(onuseResizableorSideNav'sresizableconfig), a drag writes the saved size tolocalStorageon everypointermove. Browsers deliver each changed value to every other same-origin tab as astorageevent, 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
size, and a drag changessizeon every move.storagelisteners process every intermediate size.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") andspec:AST-010FR9: 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()andexpand()finish in one event and still write at once. Observable difference: a page closed mid-drag restores the pre-drag size.Evidence
storageevents; in jsdom, a 30-move drag wrote 30 times.{"size":519,"isCollapsed":false}); jsdom: one write onpointerup,pointercancel,lostpointercaptureor the handle's unmount, none mid-drag.ResizeHandle.test.tsx; release, same-batch, unmount and re-clamp cases inuseResizable.test.ts, each asserting one final write. An older test now ends its gesture before reading storage.Scope
Writing rubric results
Testing
Local gates at
1a138a9(one commit on maindade717c5; the patch is byte-identical to the previous head'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 isutils.test.ts, which also times out alone on maindade717c5(the open test(Resizable): load the package root while the file is collected, not inside a timed test #8471 fixes it).pnpm build,pnpm -F @astryxdesign/core typecheck,pnpm check:knowledge,pnpm lint(check:repoandeslint .: 0 errors, none in changed files),prettier --check,check:changesetsand changeset coverage pass.Core/Hooks/useResizable, Structured Percent Sizing), checking the serveduseResizable.tson each run:storageevents 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}.a587813542:pnpm test:ui17,066/17,070 andpnpm test:node14,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.