Repository navigation
[drawer] Fix Shadow DOM swipe gestures - #5360
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,470.08 ms -30.88 ms(-2.1%) | Renders: 78 (+0) | Paint: 2,302.97 ms -50.27 ms(-2.1%) No significant changes — details Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
@claude review |
flaviendelangle
left a comment
There was a problem hiding this comment.
PR review
The fix itself is sound: routing every point hit-test through the element's getRootNode() is the right shape for shadow DOM, all five converted call sites are consistent with each other, and the downstream traversal helpers (contains, findScrollableTouchTarget, hasScrollableAncestor) are already shadow-safe, so nothing regresses in the light-DOM path. Nothing is merge-blocking. The one substantive gap is coverage: I reverted each hunk individually and only one of the five converted call sites is actually pinned by a test — including the canStart path that is the mechanism behind #5359, and the entire second commit.
Verification run locally on the PR head: DrawerViewport + full src/drawer suites green in jsdom and chromium (286 tests), tsc --noEmit clean on packages/react, eslint clean on all five changed files.
Bugs (1)
1. ℹ️ Hit testing still stops at the first shadow boundary
Location: packages/react/src/utils/getElementAtPoint.ts:8
return typeof root?.elementFromPoint === 'function' ? root.elementFromPoint(x, y) : null;elementFromPoint on a Document or ShadowRoot retargets the result into that tree, so it descends exactly one level. If a consumer renders a web component inside Drawer.Popup and puts data-base-ui-swipe-ignore on an element inside that component's shadow tree, elementAtPoint resolves to the component's host and isSwipeIgnoredTarget's closest() never sees the marker. This is pre-existing (light-DOM drawers had it before the PR), and the virtual-keyboard path is insulated because it falls back to resolveKeyboardTouchTarget(getTarget(event.nativeEvent)), which is composed — but DrawerViewport.onTouchStart has no such fallback for the ignore check.
Failure scenario: A user embeds a <my-media-player> custom element with data-base-ui-swipe-ignore on its internal scrubber inside a bottom drawer; dragging the scrubber starts a drawer dismiss swipe instead of scrubbing.
Fix: Optional, and fine to leave for a follow-up. If you want it composed, loop into the hit element's own shadow root:
let element = root.elementFromPoint(x, y);
while (element?.shadowRoot) {
const inner = element.shadowRoot.elementFromPoint(x, y);
if (!inner || inner === element) break;
element = inner;
}
return element;Tests (1)
1. 🟠 Only one of five converted hit-test call sites is covered
Location: packages/react/src/drawer/viewport/DrawerViewport.test.tsx:251
I reverted each hunk individually against the PR head and re-ran src/drawer in chromium (286 tests). Only onTouchStart is pinned — the new test fails without its hunk, as intended. Everything else stays green when reverted:
| Reverted hunk | Suite result |
|---|---|
DrawerViewport.tsx:357 (canStart) |
286 passed |
DrawerViewport.tsx:874 (onPointerDown) |
not separately isolated, but shares the untested pointer path |
useSwipeDismiss.ts:349 (getTargetAtPoint) |
286 passed |
DrawerVirtualKeyboardProvider.tsx (whole commit fc614a6) |
55 passed |
canStart is the notable one. It is the branch that returns false because contains(popupElement, elementAtPoint) fails against the retargeted host — i.e. the mechanism that actually blocks the swipe reported in #5359 — and the PR ships no test for it. The virtual-keyboard commit ships no test at all; every existing VKB test stubs document.elementFromPoint with the drawer in the light DOM, so getRootNode() resolves to document and the stub is hit either way.
Failure scenario: Someone later "restores" ownerDocument(...) in canStart or in resolveKeyboardTouchTargetFromPoint to satisfy the AGENTS.md owner-utility rule, CI stays green, and shadow-DOM swipe silently regresses to the state of #5359.
Fix: Add a chromium test rendering into a real attachShadow root with laid-out popup geometry (no elementFromPoint stubbing) that drives a mouse pointer swipe through canStart, plus a shadow-root variant of one existing VKB tap-to-focus test (stub shadowRoot.elementFromPoint the way the current tests stub document.elementFromPoint). Note that an unstyled popup has no usable hit geometry — give the popup and the shadow host explicit sizes, or stub the shadow root's elementFromPoint as the new test does.
Simplifications (1)
1. 🟡 Derive the virtual-keyboard root from rootElement, not event.currentTarget
Location: packages/react/src/drawer/virtual-keyboard-provider/DrawerVirtualKeyboardProvider.tsx:571
const root = event.currentTarget.getRootNode();rootElement is already null-guarded eight lines above and is what the rest of this callback uses for the contains(rootElement, keyboardTarget.focusTarget) checks. event.currentTarget only happens to be the same element because DrawerViewport is currently the sole caller of virtualKeyboard.onTouchEnd; the coupling isn't visible from the provider.
Failure scenario: A future component forwards its touch events into the provider — Drawer.SwipeArea is the obvious candidate, and it renders outside Drawer.Portal — so currentTarget sits in the light DOM while the drawer is portaled into a shadow root. The lift-point hit test then queries the wrong tree, pointTarget comes back null, and tap-to-focus silently falls back to the touchstart target.
Fix: const root = rootElement.getRootNode(); and drop the currentTarget read.
Docs (1)
1. 🟡 No comment records why getRootNode() replaces ownerDocument()
Location: packages/react/src/utils/getElementAtPoint.ts:3
AGENTS.md instructs contributors (and agents) to "always use the owner utilities ownerDocument and ownerWindow". This PR deliberately goes the other way for hit testing, at five call sites, with no note explaining that a Document retargets shadow content to the host and a ShadowRoot does not. The repo already sets the precedent for exactly this kind of one-liner — packages/react/src/utils/scrollable.ts:46 and :66 both carry a comment explaining why getParentNode is used instead of parentElement.
Failure scenario: A contributor reading getElementAtPoint(popupElement.getRootNode(), ...) next to ownerDocument(popupElement) on the adjacent line reads it as an inconsistency and normalizes it back, reintroducing #5359 with a green CI.
Fix: Add a one-line comment above getElementAtPoint, e.g. // The root node, not the document: 'Document.elementFromPoint' retargets shadow content to the host element, which then fails the 'contains()' check against a popup inside that shadow root.
Verdict
Approve after nits - the shadow-root routing is correct and green across jsdom and chromium; the outstanding items are a real coverage gap on four of five converted call sites and two small clarity fixes.
🤖 Review generated with Claude Code
|
@claude review low |
PR reviewNo findings. The switch from VerdictApprove — the hit-test root change is consistent across all call sites with no regression for the non-shadow path. 🤖 Review generated with Claude Code |
Ports the six applicable Drawer fixes from the base-ui v1.7.0 release: - mui/base-ui#5105: reliable swipe-to-open — first-move re-anchoring is now gated on trackDrag (the SwipeArea passes trackDrag: false, so a flick whose whole travel lands in the first move still registers), and sawPrimaryButtonsOnMove initializes from the event type. - mui/base-ui#5308: drag styles are only rewritten when the offset actually changed, fixing the snap point jump when the pointer is pinned at a screen edge. The swipeThreshold function is snapshotted at gesture start. - mui/base-ui#5257: cross-axis touch arbitration rewritten (shouldYieldTouchMove) — 6px slop / 2px bias, one-shot attribution per gesture, non-cancelable moves yield to native scroll, and no preventDefault until an axis passes the slop (iOS kills native scrolling for the whole gesture otherwise). - mui/base-ui#5360: elementFromPoint resolves through getRootNode() so swipe gestures work inside shadow DOM. - mui/base-ui#5112: the popup no longer flashes fully open for a frame during a swipe-area open — resetAfterOpen skips the movement-var reset while the SwipeArea drives the gesture (swipeAreaActive), and the SwipeArea re-asserts its styles when the popup (re)mounts. - mui/base-ui#5179: virtual keyboard scroll handling rework for focus moves while the keyboard is open — interval realign passes, preemptive focus geometry override to neutralize WebKit's reveal scroll, window scroll pinning, programmatic-focus flag, settle-watching scroll bookkeeping. The SwipeArea outside-press guard is now deterministic (capture-phase pointerdown/click listeners + isVirtualClick) instead of a 300ms timer. Not ported (React-only): mui/base-ui#5109, Drawer.Handle/createHandle detached triggers, bundle-size refactors. Co-Authored-By: Claude Fable 5 <[email protected]>
Port the latest Base UI `DrawerVirtualKeyboardProvider` changes: - Remove the extra keyboard scroll slack; pad by the overlap on top of at least the visibility margin (mui/base-ui#5768). - Reapply `preventScroll` on native focus before `focusin` for iOS 27, and after a tapped label refocuses its control (mui/base-ui#5769). - Track the keyboard across Chrome on iOS resizing the layout viewport, with an `svh` probe, a `resizing` guard and a window resize listener (mui/base-ui#5774). - Find the scroll container across shadow roots (mui/base-ui#5360). Also check for DrawerViewport once DrawerContent mounts, like Base UI's popup, so a drawer that starts open no longer logs a false warning. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
#2889) * feat(Drawer): add DrawerVirtualKeyboardProvider for software keyboards The software keyboard slides over the bottom of the viewport without resizing it, so a bottom-anchored drawer — and the field the user just tapped — end up underneath it (#2877). Wrapping the drawer in `DrawerVirtualKeyboardProvider` opts into keyboard-aware focus and scroll handling: while a field inside the drawer is focused it publishes the keyboard height as `--drawer-keyboard-inset` on `DrawerViewport` (or the popup, when no viewport is used) and keeps the field scrolled into the band left visible above the keyboard, adding temporary slack to its scroller when the field would otherwise sit below the scrollable range. It also defends against WebKit: a tap on a field is focused synchronously with the field's painted geometry overridden so the native reveal cannot drag a transformed sheet, native focus moves are preempted the same way, and a modal drawer pins the page against reveal scrolls the scroll lock cannot hold. Alignment is suspended while pinch-zoomed or while a nested drawer is open, and viewport changes under 60px are treated as browser chrome rather than the keyboard. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * refactor(Drawer): pass view on the redispatched keyboard tap click Matches Base UI, falling back to an init without `view` where the window fails the realm check (jsdom). Restores lean Base UI references in the ported code. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * refactor(Drawer): require DrawerViewport for the virtual keyboard provider Matches Base UI: the viewport wraps the popup, acts as the measurement and containment root, and hosts `--drawer-keyboard-inset` for the popup and everything inside it. Warns in development when it is missing instead of falling back to the popup. * fix(Drawer): address review feedback on the virtual keyboard provider - `DrawerViewport` now remembers the element it registered on the root context. Vue nulls the template ref before `onUnmounted` runs, so the identity check against `currentElement` never matched and the root kept a detached viewport. - `useDrawerVirtualKeyboard` resolves `getComputedStyle` / `matchMedia` from the element's own window, like the rest of the composable. - Tests restore fake timers, `innerHeight`, `scrollTo`, `scrollY` and `elementFromPoint` in `afterEach` so cases stay order-independent, and a new case covers the viewport teardown. * test(Drawer): restore the original innerHeight descriptor after keyboard tests jsdom defines `window.innerHeight` as an own property, so deleting it in teardown left the window without one. Capture the descriptor before stubbing and put it back. Co-Authored-By: Claude Fable 5.1 <[email protected]> * fix(Drawer): sync the virtual keyboard provider with upstream Base UI Port the latest Base UI `DrawerVirtualKeyboardProvider` changes: - Remove the extra keyboard scroll slack; pad by the overlap on top of at least the visibility margin (mui/base-ui#5768). - Reapply `preventScroll` on native focus before `focusin` for iOS 27, and after a tapped label refocuses its control (mui/base-ui#5769). - Track the keyboard across Chrome on iOS resizing the layout viewport, with an `svh` probe, a `resizing` guard and a window resize listener (mui/base-ui#5774). - Find the scroll container across shadow roots (mui/base-ui#5360). Also check for DrawerViewport once DrawerContent mounts, like Base UI's popup, so a drawer that starts open no longer logs a false warning.
Fixes #5359
Changes