-
-
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
[material-ui][Tabs] ScrollbarSize.setMeasurements performs a null-check for nodeRef before setting scrollbarHeight #42512
Conversation
I don't understand this fix. Looking at the code, it seems that this shouldn't be possible to happen in the first place, so that the problem is not in this file, so it shouldn't be changed. What's the root problem? |
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.
Need a test case. It might be because the reproduction isn't depending on #36485
The reproduction is depending on a version of MUI released well after #36485 was merged. The original bug report #41388 includes multiple comments from people encountering the same error. I will continue to work on a test case. |
|
||
// https://github.com/mui/material-ui/issues/41388 | ||
it('should allow a user to click a scrollable Tab without an error', async function test() { | ||
function DynamicScrollableTabs() { |
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.
Analogous to DynamicScrollableTabs used in the live example.
// Click on the Item Seven Tab | ||
// In the test fixture, this fails with | ||
// TypeError: Cannot read properties of null (reading 'offsetHeight') | ||
await user.click(tab7); |
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.
This test is analogous to https://github.com/nicholeuf/mui-test-fixture-41388/blob/main/app/page.test.tsx. The user click action fails in the live example test fixture and succeeds here.
The latest live example uses the latest mui release and therefore includes #36485. A test case was created analogous to the live example test case that is failing with latest mui. |
While it doesn't appear to be possible for the nodeRef to be null, it is clearly happening in the live example. It is also happening for other people, based on the comments. Based on the caveats https://react.dev/reference/react/useRef#caveats, could we possibly be in a situation where the ref is being referenced during rendering? The error in the live example happens when the active tab is changed by clicking another tab. |
Netlify deploy previewhttps://deploy-preview-42512--material-ui.netlify.app/ Bundle size reportDetails of bundle changes (Toolpad) |
@@ -1438,5 +1441,93 @@ describe('<Tabs />', () => { | |||
expect(hasLeftScrollButton(container)).to.equal(false); | |||
expect(hasRightScrollButton(container)).to.equal(false); | |||
}); | |||
|
|||
// https://github.com/mui/material-ui/issues/41388 | |||
it('should allow a user to click a scrollable Tab without an error', async function test() { |
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.
This test passes in next
branch HEAD, which means it isn't testing what's needed. It should fail in base branch.
please merge this 👯 |
'Item Ten', | ||
]; | ||
return ( | ||
<Container maxWidth="sm"> |
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.
to simplify
@@ -1,6 +1,7 @@ | |||
import * as React from 'react'; | |||
import { expect } from 'chai'; | |||
import { spy } from 'sinon'; | |||
import userEvent from '@testing-library/user-event'; |
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.
We don't allow this dependency, I mean to the best of my knowledge, we trigger each event instead.
import Box from '@mui/material/Box'; | ||
import Container from '@mui/material/Container'; |
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.
To simplify
import Box from '@mui/material/Box'; | |
import Container from '@mui/material/Container'; |
We appreciate the work spent on this but I'm closing. We are not adding defensive checks for things that React should guarantee to be unreachable. Instead, let's focus on #41388. We need a reproduction. |
But this is not working in react 19 at all, you preferred to block people than just add one line in the meantime react do something? |
@joacub If you have a reproduction, please contribute it to #41388. We can't change the source without being able to reproduce the problems. We need to have this rule because nothing great comes from not understanding what's going on, I have never seen great work being done without it, e.g. we need to write a test case so an engineer who never worked on the codebase doesn't introduce regressions. In this instance, something is not right, a defensive check is not missing. To be blunt, I think MUI should be here to push the envelope, getting this right should take priority over fixing things quickly and dirty. If we take a long-term lens, I think going forward with this PR would be perceived by others as: amateur hours, at least this is how I would perceive it, I wouldn't touch that library. |
|
but @oliviertassinari , bugs are every where you can not be so straight about no implementing something that solves an issue in a particular case like this, also reference can be null at some point for any reason and some mutabilities so I don't think there is a issue adding any defensive check just in case. |
Resolves #41388 by defensively checking the nodeRef.current in the setMeasurements function.
Test fixture demonstrating the error: https://github.com/nicholeuf/mui-test-fixture-41388
Live example: https://codesandbox.io/p/devbox/exciting-wiles-m75jsd?file=%2Fapp%2Fpage.test.tsx%3A41%2C1