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

[material-ui][Tabs] ScrollbarSize.setMeasurements performs a null-check for nodeRef before setting scrollbarHeight #42512

Closed
wants to merge 3 commits into from

Conversation

nicholeuf
Copy link

@nicholeuf nicholeuf commented Jun 3, 2024

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

@nicholeuf nicholeuf changed the title ScrollbarSize.setMeasurements performs a null-check for nodeRef before setting scrollbarHeight [material-ui][Tabs] ScrollbarSize.setMeasurements performs a null-check for nodeRef before setting scrollbarHeight Jun 3, 2024
@oliviertassinari oliviertassinari added component: tabs This is the name of the generic UI component, not the React module! PR: needs test The pull request can't be merged labels Jun 4, 2024
@oliviertassinari
Copy link
Member

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?

Copy link
Member

@oliviertassinari oliviertassinari left a 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

@nicholeuf
Copy link
Author

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() {
Copy link
Author

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);
Copy link
Author

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.

@nicholeuf
Copy link
Author

nicholeuf commented Jun 7, 2024

Need a test case. It might be because the reproduction isn't depending on #36485

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.

@nicholeuf
Copy link
Author

nicholeuf commented Jun 7, 2024

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?

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.

Screenshot 2024-06-07 at 4 18 25 PM

@mui-bot
Copy link

mui-bot commented Jun 15, 2024

Netlify deploy preview

https://deploy-preview-42512--material-ui.netlify.app/

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against c22554f

@@ -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() {
Copy link
Member

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.

@ZeeshanTamboli ZeeshanTamboli added package: material-ui Specific to @mui/material and removed PR: needs test The pull request can't be merged labels Jun 15, 2024
@joacub
Copy link

joacub commented Jun 23, 2024

please merge this 👯

'Item Ten',
];
return (
<Container maxWidth="sm">
Copy link
Member

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';
Copy link
Member

@oliviertassinari oliviertassinari Jun 23, 2024

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.

Comment on lines +13 to +14
import Box from '@mui/material/Box';
import Container from '@mui/material/Container';
Copy link
Member

@oliviertassinari oliviertassinari Jun 23, 2024

Choose a reason for hiding this comment

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

To simplify

Suggested change
import Box from '@mui/material/Box';
import Container from '@mui/material/Container';

@oliviertassinari oliviertassinari added the PR: needs test The pull request can't be merged label Jun 23, 2024
@oliviertassinari
Copy link
Member

oliviertassinari commented Jun 23, 2024

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.

@joacub
Copy link

joacub commented Jun 23, 2024

I'm closing, in any case, we are not adding defensive checks for things that React should guarantee to be unreachable.

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?

@oliviertassinari
Copy link
Member

oliviertassinari commented Jun 23, 2024

@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.

@joacub
Copy link

joacub commented Jun 23, 2024

@joacub We can't change the source without being able to reproduce the problems. If you have a reproduction, please contribute it to #41388. React 19 seems to work: https://codesandbox.io/p/devbox/exciting-wiles-forked-td8mq5?file=%2Fpackage.json%3A26%2C39 in its simplest case.

image

@joacub
Copy link

joacub commented Jun 23, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: tabs This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material PR: needs test The pull request can't be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[material-ui][Tabs] Scrollable variant fails test when clicking the tab (error reading 'offsetHeight')
5 participants