Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

xavier-villelegier
Copy link

@xavier-villelegier xavier-villelegier commented Dec 29, 2021

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 here
https://github.com/mui-org/material-ui/blob/98c9aad08696f44976f55aa1e254d013df6c38e1/packages/mui-material/src/SwipeableDrawer/SwipeableDrawer.js#L296-L300

but not in handleBodyTouchEnd yet

Tested locally in multiple cases and it works fine 👌

Cheers from Doctolib ✌️

@mui-pr-bot
Copy link

mui-pr-bot commented Dec 29, 2021

Details of bundle changes

Generated by 🚫 dangerJS against fcf2a8a

@oliviertassinari oliviertassinari added the status: waiting for author Issue with insufficient information label Dec 29, 2021
@oliviertassinari
Copy link
Member

oliviertassinari commented Dec 29, 2021

@xavier-villelegier Thanks for the PR, however, we miss a reproduction at minimum in order to be able to move forward.

@oliviertassinari oliviertassinari added component: drawer This is the name of the generic UI component, not the React module! component: SwipeableDrawer The React component. labels Dec 29, 2021
@@ -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) {
Copy link
Member

@oliviertassinari oliviertassinari Dec 29, 2021

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.

https://github.com/mui-org/material-ui/blob/fcf2a8a5c90e6a975b0a8c391aa2f95f6e860b15/packages/mui-material/src/SwipeableDrawer/SwipeableDrawer.js#L510

I hope it illustrates why #30440 (comment) (not the only reason, e.g. so we can add a test case)

Copy link
Author

@xavier-villelegier xavier-villelegier Dec 30, 2021

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

image
image

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

@siriwatknp
Copy link
Member

👋 The migration PR has been merged.

Please follow these steps to make sure that the contents are all updated. (Sorry for the inconvenience)

  1. pull latest master from upstream to your branch
  2. if your PR has changes on the *.md or demo files, you are likely to encounter conflict because all of them have been moved to the new folder.
    2.1 revert the change on those markdown files you did
    2.2 pull latest master from upstream (you should not see conflict)
    2.3 make the changes again at docs/data/material/*
  3. run yarn docs:api
    • you might see the changes in docs/pages/material/api/* if your PR touches some of the components
    • it is okay if there is no changes

If you are struggle with the steps above, feel free to tag @siriwatknp

@xavier-villelegier
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: drawer This is the name of the generic UI component, not the React module! component: SwipeableDrawer The React component. status: waiting for author Issue with insufficient information
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants