Skip to content

[drawer] Fix interrupted swipe dismiss cleanup - #4467

Merged
atomiks merged 3 commits into
mui:masterfrom
lunaxislu:fix-drawer-swipe-cancel-cleanup
Mar 30, 2026
Merged

atomiks merged 3 commits into
mui:masterfrom
lunaxislu:fix-drawer-swipe-cancel-cleanup

Conversation

@lunaxislu

@lunaxislu lunaxislu commented Mar 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4471

Summary

Fix interrupted drawer swipe-open interactions so outside press dismissal is restored even when the swipe is canceled before normal release cleanup runs.

Changes

  • add an onCancel hook to useSwipeDismiss
  • reuse release-equivalent cleanup in Drawer.SwipeArea for both release and cancel paths
  • add regression coverage for interrupted swipe-open dismissal recovery
  • add regression coverage for context-menu-interrupted swipe-open dismissal recovery

Reproduction

  1. Start opening a drawer with Drawer.SwipeArea
  2. Interrupt the gesture before normal release cleanup finishes
  3. Click outside the drawer
  4. Before this change, outside dismiss could remain disabled
  5. After this change, outside press dismiss works again

Testing

  • mise exec [email protected] -- pnpm test:jsdom DrawerSwipeArea --no-watch
  • mise exec [email protected] -- pnpm test:jsdom useSwipeDismiss --no-watch
  • mise exec [email protected] -- pnpm exec eslint packages/react/src/utils/useSwipeDismiss.ts packages/react/src/drawer/swipe-area/DrawerSwipeArea.tsx packages/react/src/drawer/swipe-area/DrawerSwipeArea.test.tsx

@pkg-pr-new

pkg-pr-new Bot commented Mar 28, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@4467
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@4467
    

commit: 67fc4a5

@mui-bot

mui-bot commented Mar 28, 2026 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 🔺+13B(0.00%) 🔺+24B(+0.02%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Mar 28, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 67fc4a5
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/69ca3b7f4786c80008915179
😎 Deploy Preview https://deploy-preview-4467--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@lunaxislu
lunaxislu marked this pull request as draft March 28, 2026 17:41
@lunaxislu
lunaxislu marked this pull request as ready for review March 29, 2026 04:21
@lunaxislu
lunaxislu marked this pull request as draft March 29, 2026 05:07
@lunaxislu
lunaxislu marked this pull request as ready for review March 30, 2026 03:26
@atomiks atomiks added type: bug It doesn't behave as expected. component: drawer Changes related to the drawer component. labels Mar 30, 2026

atomiks commented Mar 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review (GPT-5.4)

This remains a focused bug-fix PR. The follow-up commit simplifies the local cleanup helper in Drawer.SwipeArea without changing the underlying fix, and the current tip still looks mergeable based on the full branch pass plus targeted reruns on the touched file.

1. Bugs / Issues (None)

2. Root Cause & Patch Assessment

The issue report pointed at outside-press dismissal staying disabled when a swipe-open gesture exits through the hook’s cancel path instead of the normal release path. The change in packages/react/src/utils/useSwipeDismiss.ts adds an explicit onCancel callback at the point where button-loss cancellation is detected, and packages/react/src/drawer/swipe-area/DrawerSwipeArea.tsx funnels both onRelease and onCancel through the same cleanup path. That still matches the reported failure mode and keeps the release/cancel behavior aligned instead of duplicating the cleanup sequence in two places.

The latest follow-up commit stays in packages/react/src/drawer/swipe-area/DrawerSwipeArea.tsx and only refactors that cleanup into a plain function plus a small reset helper. I do not see evidence that it changes the runtime behavior of the fix.

3. Simplification Opportunities

Handled: the current tip drops the unnecessary useStableCallback wrapper around finishSwipeInteraction, uses onCancel: finishSwipeInteraction, and reuses resetSwipeInteractionState() in the disabled-effect path. That makes the cleanup flow easier to read without widening the behavior surface.

4. Edge Cases Worth Noting

The regression coverage in packages/react/src/drawer/swipe-area/DrawerSwipeArea.test.tsx still exercises the two interruption modes that matter most here: a non-primary-button takeover during the swipe and a context-menu interruption after the drawer has already been opened by the gesture. That remains the right boundary to test because the bug only appears once outside-dismiss has been disabled and the open-state cleanup has to recover from a non-release exit.

Merge Confidence Score

Overall merge confidence is 4/5. I still did not find a branch-relevant correctness issue in the diff, and after the follow-up cleanup commit pnpm test:jsdom DrawerSwipeArea --no-watch, pnpm test:chromium DrawerSwipeArea --no-watch, and pnpm exec eslint packages/react/src/drawer/swipe-area/DrawerSwipeArea.tsx all passed. I’d still be comfortable merging this as-is.

@atomiks atomiks 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.

Thanks for the fix @lunaxislu

@atomiks
atomiks merged commit 49ae681 into mui:master Mar 30, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: drawer Changes related to the drawer component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[drawer] Outside press dismiss stops working after interrupted swipe-open

3 participants