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

[ButtonBase] Start ripple pulsation only after mount #31950

Merged
merged 1 commit into from
Mar 24, 2022

Conversation

m4theushw
Copy link
Member

@m4theushw m4theushw commented Mar 22, 2022

Before: https://codesandbox.io/s/checkboxes-material-demo-forked-xrw1ff?file=/demo.tsx

After: https://codesandbox.io/s/checkboxes-material-demo-forked-vg2d2u?file=/demo.tsx

In React 18, any component derived from ButtonBase that receives focus during mount will crash when rippleRef.current.pulsate() is called. This happens because the TouchRipple is rendered conditionally to save resources on SSR. However, in React 18, the effect that sets the focus runs slightly faster than the effect responsible for updating the state to render the ripple. More information see facebook/react#24102 (comment)

I noticed this bug when testing the compatibility of the DataGrid with React 18. In our case, we use Checkbox and when a cell switches from view to edit mode we need to focus the input component. To reproduce the crash in the DataGrid follow the steps below:

  1. Open https://deploy-preview-4155--material-ui-x.netlify.app/components/data-grid/demo/
  2. Scroll to the right to see the "Is filled" column
  3. Click once in one of the cells of the "Is filled" column
  4. Press Enter
  5. 💥

@mui-bot
Copy link

mui-bot commented Mar 22, 2022

Details of bundle changes

Generated by 🚫 dangerJS against 603aa8b

@m4theushw m4theushw changed the title [ButtonBase] Start ripple only after mount [ButtonBase] Start ripple pulsation only after mount Mar 23, 2022
@danilo-leal danilo-leal added the component: ButtonBase The React component. label Mar 23, 2022
Copy link
Member

@siriwatknp siriwatknp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good. Is it possible to test at this point?

@MichaelDeBoey
Copy link
Contributor

@mnajdova Sorry to ping you when this PR is already closed for more than a year.

Just out of curiosity: I was wondering if there is a specific reason why you went with the useEffect + useState instead of checking if rippleRef.current has a value (like we already do a couple of lines lower: https://github.com/mui/material-ui/pull/31950/files#diff-dedcd6c4fe29d61278a0e914afce0473b71a38e6621469a736af9436989f6a1aR156)? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: ButtonBase The React component.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants