Skip to content

fix(ResizeHandle): keep the drag when the cursor crosses an embedded frame - #5297

Merged
cixzhang merged 1 commit into
mainfrom
resize-pointer-capture
Sep 1, 2026
Merged

cixzhang merged 1 commit into
mainfrom
resize-pointer-capture

Conversation

@cixzhang

@cixzhang cixzhang commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Why

ResizeHandle started a drag on pointerdown and then listened on window for
pointermove/pointerup, without ever calling setPointerCapture. Without
capture the browser hit-tests every later pointer event, so the moment the
cursor crosses an <iframe> inside the resizable region those events are
dispatched into the guest document and the host window listener stops
hearing them. The drag dies mid-gesture while still looking armed. It bites any
consumer whose resizable region can contain a frame — a preview pane, an
embedded app.

The cursor leaves the handle more often than it sounds: the divider only tracks
the pointer while the panel can still follow it, so any drag past maxSizePx
(or down to minSizePx, or faster than layout) puts the pointer over the
content pane.

Measured

New story Lab/Resizable → WithEmbeddedFrame, driven in Chromium with
Playwright: press on the handle, drag right until the panel hits its 520px max,
keep going 25 × 8px so the cursor is genuinely over the frame, release there.

before after
pointermove events the host received while the cursor was over the frame 0 / 25 25 / 25
panel width after the drag (from 200px) 200px — never moved 520px — full travel, clamped at max
pointerup heard by the host no yes
data-resizing after release still set cleared
body cursor / user-select after release col-resize / none cleared

The panel never moves at all in the "before" column because the grab zone is
biased onto the pill on the panel side, so the very first move of the drag
already lands the cursor over the frame.

What

pointerdown now takes pointer capture on the grab zone, and the
move/up/cancel handlers moved onto that element.

Where the listeners went, and why. A captured pointer's events are
delivered to the capturing element and then bubble, so listeners on the element
and listeners on window would both fire — keeping both would double-handle,
and keeping only window would leave the drag at the mercy of any
stopPropagation between the handle and the top. They live on the element, the
same shape as Slider and BottomSheet.

Three behaviors the old code had, and where they went:

  • Unmount mid-drag. Removing the capturing element implicitly releases the
    pointer and takes React's listeners with it, so an in-flight drag stops
    driving the region on its own; the unmount effect stays only to release the
    body cursor/user-select overrides, which do not live on the element.
  • pointercancel. Still ends the drag without signalling a resize end.
    lostpointercapture routes to the same path — it also fires on the implicit
    release after every pointerup/pointercancel, by which point the drag is
    already cleared and it is a no-op.
  • Foreign pointers. Capture is per-pointer, so the handlers ignore moves
    from a pointer that does not own the drag.

No API change; keyboard resizing, RTL delta mapping and the grab-zone geometry
are untouched.

Testing

ResizeHandle.test.tsx covers capture taken on pointerdown, the drag driven
and ended from the element, pointercancel/lostpointercapture teardown,
foreign-pointer moves ignored, and unmount mid-drag. One SideNav test needed
updating — it dispatched its synthetic drag at document. Full packages/core
suite, typecheck and lint pass.

Adjacent, not touched here

Two other drags in core hold the same window-listener shape and will drop the
same way over a frame: useTableColumnResize and the Lightbox pan. Left
alone so this stays one component — worth asking separately whether they should
all share one drag hook.

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

vercel Bot commented Aug 21, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Aug 30, 2026 9:00pm

Request Review

@github-actions

github-actions Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

Resizable (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 808 -
Complexity N/A Very High (98) -
SideNav (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 2049 -
Complexity N/A Very High (213) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.8KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

126 added · 0 removed. View the report

To accept these exact frames: /accept-visual 33335001095/1 <reason>

Added — After
Added — After visual regression frame

Added — After
Added — After visual regression frame

Added — After
Added — After visual regression frame


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

github-actions Bot added a commit that referenced this pull request Aug 21, 2026
@cixzhang
cixzhang marked this pull request as ready for review August 30, 2026 20:49
…frame

The handle listened for pointermove/pointerup on window without taking
pointer capture, so the browser hit-tested every later event and an iframe
inside the resizable region swallowed the rest of the gesture into its own
document. Take capture on the grab zone at pointerdown and deliver the
move/up/cancel handlers there, as Slider and BottomSheet do.
@cixzhang

Copy link
Copy Markdown
Contributor Author

/accept-visual

@github-actions

Copy link
Copy Markdown
Contributor

Visual acceptance refused: copy the exact /accept-visual <run>/<attempt> <reason> command from the report.

@cixzhang

Copy link
Copy Markdown
Contributor Author

/accept-visual 33335001095/1 Expected ResizeHandle pointer-capture coverage.

github-actions Bot added a commit that referenced this pull request Aug 30, 2026
@github-actions github-actions Bot added the visual-approved Current visual bundle has an explicit acceptance record label Aug 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Visual changes accepted for d023d972c5b8. A new push invalidates this approval; after merge, the reviewed AFTER frames must reproduce before the baseline is promoted.

@cixzhang
cixzhang merged commit 560d733 into main Sep 1, 2026
24 checks passed
github-actions Bot added a commit that referenced this pull request Sep 1, 2026
@github-actions
github-actions Bot deleted the resize-pointer-capture branch September 2, 2026 06:27

This branch was successfully deployed

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

Labels

CLA Signed This label is managed by the Meta Open Source bot. visual-approved Current visual bundle has an explicit acceptance record

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant