-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[useMediaQuery] Workaround Safari wrong implementation of matchMedia #17315
Conversation
…is may have happened in cases such as if a component unmounts when a window resizes. Pattern used is from: https://reactjs.org/docs/hooks-faq.html#is-it-safe-to-omit-functions-from-the-list-of-dependencies
Details of bundle changes.Comparing: 1eff1cf...a52f004
|
Thank you for opening this pull request. Do you have a reproduction? I thought the handler won't be called once I called |
This issue seems to be happening in Safari and not Chrome, at least on macOS. It seems that the listener is being triggered after the last render, but before the cleanup. Here is a sample Michael put together. In Safari, if you resize the window, you'll see a console error: |
I could reproduce with the link. We might want to report this issue to the Safari team and add a comment about it, so we could remove the defensive check, at some point, in the future. |
I have frozen the reproduction version of Material-UI to v4.4.0 so we can test the reproduction somewhere in the future without the fix and a more recent version of Safari: https://codepen.io/oliviertassinari/pen/mdbqNLQ. |
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.
I need to check if this one of the cases where we should use the useSubscription hook. I think I remember that this was one of the use cases that hook already prevented.
I tried to run this on Safari 14.0 (16610.1.21.1.2), and I could not see any errors in the console. Except some errors I think might be from CodePen itself, so I tried in CodeSandBox, and works there too (https://codesandbox.io/s/runtime-wildflower-6bzns) |
For useMediaQuery(), don't call setState() once unmounting begins. This may have happened in cases such as if a component unmounts when a window resizes.