-
-
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
[Tabs] Fix null reference in ScrollbarSize after unmounting #36485
Conversation
Netlify deploy previewhttps://deploy-preview-36485--material-ui.netlify.app/ Bundle size report |
const setMeasurements = () => { | ||
scrollbarHeight.current = nodeRef.current.offsetHeight - nodeRef.current.clientHeight; | ||
const setMeasurements = (element) => { | ||
scrollbarHeight.current = element.offsetHeight - element.clientHeight; | ||
}; | ||
|
||
React.useEffect(() => { |
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.
Would it be a simpler fix with a one-line change? Like we did in #25619 since with layout effect, the cleanup runs synchronously.
React.useEffect(() => { | |
useEnhancedEffect(() => { |
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.
@oliviertassinari Tried to avoid synchronous effect if it can be avoided in another way because it can impose unnecessary impact on performance. In this case, the effect would not be called frequently so it would be ok to do that in this feature I think. Thanks for the review.
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 feel that the synchronous layout effect makes more sense since we want to detect layout changes. It also simplifies a bit the logic, as it guarantees that the element is defined.
@mnajdova Sorry I accidentally removed you from reviewers while requesting review again. |
The logic makes sense to me, but it's no longer my role to review PRs. I have removed myself. |
I hope it can get merged soon because it has a very minor change. |
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.
It's a great first pull request on Material UI 👌 Thank you for working on it!
Closes #26587
As per https://reactjs.org/blog/2020/08/10/react-v17-rc.html#effect-cleanup-timing, timeout callback set by
debounce
can be called before effect cleanup, which can leads to callingsetMeasurements
withnodeRef.current
unset.