-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SwipeableDrawer] Fix React 18 issues #34505
Changes from all commits
78bd05c
09e982f
313f572
33fffb4
71683f8
c5a8e9b
5b05a36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import * as React from 'react'; | ||
import { flushSync } from 'react-dom'; | ||
import PropTypes from 'prop-types'; | ||
import { elementTypeAcceptingRef } from '@mui/utils'; | ||
import { useThemeProps } from '@mui/system'; | ||
|
@@ -234,7 +235,9 @@ const SwipeableDrawer = React.forwardRef(function SwipeableDrawer(inProps, ref) | |
} | ||
claimedSwipeInstance = null; | ||
touchDetected.current = false; | ||
setMaybeSwiping(false); | ||
flushSync(() => { | ||
setMaybeSwiping(false); | ||
}); | ||
|
||
// The swipe wasn't started. | ||
if (!swipeInstance.current.isSwiping) { | ||
|
@@ -488,7 +491,10 @@ const SwipeableDrawer = React.forwardRef(function SwipeableDrawer(inProps, ref) | |
swipeInstance.current.startX = currentX; | ||
swipeInstance.current.startY = currentY; | ||
|
||
setMaybeSwiping(true); | ||
flushSync(() => { | ||
setMaybeSwiping(true); | ||
}); | ||
|
||
if (!open && paperRef.current) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assumed that here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use |
||
// The ref may be null when a parent component updates while swiping. | ||
setPosition( | ||
|
@@ -554,6 +560,11 @@ const SwipeableDrawer = React.forwardRef(function SwipeableDrawer(inProps, ref) | |
...BackdropProps, | ||
ref: backdropRef, | ||
}, | ||
// Ensures that paperRef.current will be defined inside the touch start event handler | ||
// See https://github.com/mui/material-ui/issues/30414 for more information | ||
...(variant === 'temporary' && { | ||
keepMounted: true, | ||
}), | ||
...ModalPropsProp, | ||
}} | ||
hideBackdrop={hideBackdrop} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes the part of the issue where the partially opened drawer (> hysteresis) is not opening the drawer completely. Could probably go as a standalone fix.