Skip to content

fix(useResizable): a drag saves its size once, when it ends, not on every move - #7782

Merged
cixzhang merged 1 commit into
meta:mainfrom
vjeux:resizable-persist-on-drag-end
Oct 31, 2026
Merged

cixzhang merged 1 commit into
meta:mainfrom
vjeux:resizable-persist-on-drag-end

Conversation

@vjeux

@vjeux vjeux commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

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

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • 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 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: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.

@vercel

vercel Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Oct 31, 2026 9:05pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 21, 2026
@astracat-bot

astracat-bot Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 31, 2026, 9:10 PM UTC

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

Preview availability: this branch's preview address cannot be known in advance; open the preview from Vercel's comment on this pull request.

Component Size

Component Import before Import after Delta CSS before CSS after Delta
core/ResizeHandle 25.6KB 25.6KB +1B 4.0KB 4.0KB 0B
core/SideNav 66.7KB 66.8KB +73B 10.9KB 10.9KB 0B

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 Summary

Gzip figures measure each package's entry file, not the code an import pulls in.

Package Entry (ESM) Entry gzip before Entry gzip after Delta
@astryxdesign/core 4.9KB 1.2KB 1.2KB 0B
Package stylesheet Gzip before Gzip after Delta
@astryxdesign/core 36.0KB 36.0KB 0B

Published Package Size

Package Download before Download after Delta Unpacked before Unpacked after Delta Files
@astryxdesign/core 6.52MB 6.52MB +1.2KB (+0.0%) 27.71MB 27.72MB +4.0KB (+0.0%) 3699

10 other published packages are unchanged.

Download is the gzip tarball npm fetches; unpacked is what lands in node_modules.

Accessibility Audit

Status: Accessibility did not run on this pull request; add ci:run-a11y to run it. It runs after merges to main and before each release.


Generated by PR Enrichment workflow | View full report

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

@vjeux

vjeux commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

No inline comments, so I'm answering the one finding here. No code change.

The open question is whether spec:AST-010 FR5 covers the stored entry while a drag is still in flight. What bears on it:

  • FR5 is about which value is stored: the same resolved, clamped pixel geometry as state, paint and ARIA ("CSS-only clamping that leaves hook state outside the painted bounds is prohibited"). This branch stores exactly that value, in the unchanged shape ("Persistence representation", FR9), when the gesture ends.
  • FR7 already treats the end of a gesture as the point where it settles: "a basis change during the gesture takes effect after the gesture ends". Persistence now uses the same boundary.
  • Within the page, the stored entry only seeds a region's initial state, so no geometry depends on it mid-gesture. During a drag its only consumers are other same-origin tabs, through the storage events this change removes.
  • Every way a gesture ends still writes: pointerup, pointercancel, lostpointercapture, the handle unmounting mid-drag, and the region unmounting mid-drag. Only a document destroyed while the pointer is still held keeps the pre-drag size.
  • The strict reading and this fix cannot both hold: storing every intermediate size means writing every committed size change, and each changed write is a storage event in every other same-origin tab.

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.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

@vjeux
vjeux marked this pull request as draft October 30, 2026 03:37
@vjeux
vjeux force-pushed the resizable-persist-on-drag-end branch from 0f7c795 to aa26c91 Compare October 31, 2026 16:44
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Oct 31, 2026
@vjeux

vjeux commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

This head records the settled-size reading in component:Resizable's review check: "storage holds the last settled size and receives the final size once when a drag ends, cancels, or unmounts." spec:AST-010 FR5's text is unchanged.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, which onResizeEnd, onResizeCancel and ResizeHandle'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. |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +982 to +990
useEffect(
() => () => {
const pending = pendingWriteRef.current;
if (pending != null) {
persistState(pending.key, pending.state);
}
},
[],
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@vjeux
vjeux force-pushed the resizable-persist-on-drag-end branch from aa26c91 to 807e791 Compare October 31, 2026 18:37
@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec 807e791

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Oct 31, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@vjeux
vjeux force-pushed the resizable-persist-on-drag-end branch from 807e791 to b124f38 Compare October 31, 2026 19:15
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Oct 31, 2026
@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec b124f38

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Oct 31, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Oct 31, 2026
@cixzhang
cixzhang marked this pull request as ready for review October 31, 2026 20:14
…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.
@vjeux
vjeux force-pushed the resizable-persist-on-drag-end branch from b124f38 to 1a138a9 Compare October 31, 2026 20:56
@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec 1a138a9

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

@cixzhang
cixzhang merged commit 94eb29b into meta:main Oct 31, 2026
53 checks passed
@vjeux
vjeux deleted the resizable-persist-on-drag-end branch October 31, 2026 21:33

This branch was successfully deployed

1 active deployment
Preview — 1a138a9e Deployed Oct 31, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants