Skip to content

[swipeable drawer] External ref causes mergeSlotProps to overwrite internal ref #48009

@juraj-muravsky

Description

@juraj-muravsky

Steps to reproduce

Steps:

  1. Open this live example: https://stackblitz.com/edit/ob1sd6fc-ta22ng51?file=src%2FDemo.tsx
  2. Open the preview in a touch-enabled device or enable touch emulation in DevTools
  3. Click either "Open Test 1" or "Open Test 2" button to open either drawer
  4. Attempt to close the drawer by swiping (touch drag gesture)

Current behavior

The application crashes with the following error:
Uncaught TypeError: Cannot read properties of undefined (reading 'contains')

Expected behavior

The drawer closes

Context

From testing, this happens because mergeSlotProps does not correctly handle the callback ref returned by useForkRef, and will overwrite it with the external ref if present.

Your environment

npx @mui/envinfo
  System:
    OS: Windows 11 10.0.26100
  Binaries:
    Node: 20.19.5 - C:\nvm4w\nodejs\node.EXE
    npm: 10.8.2 - C:\nvm4w\nodejs\npm.CMD
    pnpm: Not Found
  Browsers:
    Chrome: 135.0.7049.42
  npmPackages:
    @emotion/react: ^11.14.0 => 11.14.0
    @emotion/styled: ^11.14.1 => 11.14.1
    @mui/core-downloads-tracker:  7.3.9
    @mui/lab: 7.0.1-beta.22 => 7.0.1-beta.22
    @mui/material: ^7.3.9 => 7.3.9
    @mui/private-theming:  7.3.9
    @mui/styled-engine:  7.3.9
    @mui/system:  7.3.9
    @mui/types:  7.4.12
    @mui/utils:  7.3.9
    @mui/x-date-pickers: ^7.29.4 => 7.29.4
    @mui/x-internals:  7.29.0
    @types/react: ^19.2.14 => 19.2.14
    react: ^19.2.4 => 19.2.4
    react-dom: ^19.2.4 => 19.2.4
    typescript: ^5.9.3 => 5.9.3

Search keywords: mergeSlotProps SwipeableDrawer paper ref

Metadata

Metadata

Assignees

Labels

component: SwipeableDrawerThe React component.has workaroundThere’s a bug, but users have a complete workaround, so no urgent fix or release is needed.type: bugIt doesn't behave as expected.
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions