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

[Tabs] Fix crash when used with React 18 & Suspense #33277

Merged
merged 1 commit into from
Jun 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/mui-material/src/Tabs/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,16 @@ const Tabs = React.forwardRef(function Tabs(inProps, ref) {

React.useEffect(() => {
const handleResize = debounce(() => {
updateIndicatorState();
updateScrollButtonState();
// If the Tabs component is replaced by Suspense with a fallback, the last
// ResizeObserver's handler that runs because of the change in the layout is trying to
// access a dom node that is no longer there (as the fallback component is being shown instead).
// See https://github.com/mui/material-ui/issues/33276
// TODO: Add tests that will ensure the component is not failing when
// replaced by Suspense with a fallback, once React is updated to version 18
if (tabsRef.current) {
updateIndicatorState();
updateScrollButtonState();
}
});
const win = ownerWindow(tabsRef.current);
win.addEventListener('resize', handleResize);
Expand Down