-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
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
Prevent SwipeableDrawer crash when parent update while swiping #30440
Conversation
@xavier-villelegier Thanks for the PR, however, we miss a reproduction at minimum in order to be able to move forward. |
@@ -227,7 +227,8 @@ const SwipeableDrawer = React.forwardRef(function SwipeableDrawer(inProps, ref) | |||
); | |||
|
|||
const handleBodyTouchEnd = useEventCallback((nativeEvent) => { | |||
if (!touchDetected.current) { | |||
// the ref may be null when a parent component updates while swiping | |||
if (!paperRef.current || !touchDetected.current) { |
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.
This type of defensive check usually hides root causes. To always be suspicious.
Here, I suspect that because the cleanup happens in a useEffect, it's async, but it should be a layout effect to be sync. We might have similar cleanup problems in the other components.
I hope it illustrates why #30440 (comment) (not the only reason, e.g. so we can add a test case)
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.
Hey @oliviertassinari, thanks for you answer, I definitely agree. We've inlined the component in production to check, and it's not the root cause anyway, the sentries are still there, which sounds a bit surprising 🤔 I've also tried to replace this useEffect
by a useLayoutEffect
, and still the same errors
I've tried various things to trigger the error, but no luck I didn't reproduce it yet. But it's not that edge case as we have 1k/day occurences on iOS and 1k/day on Android. Thus it doesn't look like OS-related, i'd say it's more about the react lifecycle itself
👋 The migration PR has been merged. Please follow these steps to make sure that the contents are all updated. (Sorry for the inconvenience)
If you are struggle with the steps above, feel free to tag @siriwatknp |
Closing this for now. We still have the issue on production though, we'll try to find a way to fix this on our side |
Hey hey ! 👋
We noticed a lot of sentries in getMaxTranslate because this crashes when the parent updates while the user is swiping the drawer.
This is already handled in
handleBodyTouchMove
herehttps://github.com/mui-org/material-ui/blob/98c9aad08696f44976f55aa1e254d013df6c38e1/packages/mui-material/src/SwipeableDrawer/SwipeableDrawer.js#L296-L300
but not in
handleBodyTouchEnd
yetTested locally in multiple cases and it works fine 👌
Cheers from Doctolib ✌️