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

[SliderUnstyled] TypeError Cannot read property 'getBoundingClientRect' of null #26754

Open
luminaxster opened this issue Jun 14, 2021 · 5 comments
Assignees
Labels
bug 🐛 Something doesn't work component: slider This is the name of the generic UI component, not the React module!

Comments

@luminaxster
Copy link
Contributor

When using controlled sliders, while interacting with them, I continuously get errors on this line:
https://github.com/mui-org/material-ui/blob/2d4d0663ff1ed732e6952705d0e23eda13ae25ea/packages/material-ui-unstyled/src/SliderUnstyled/SliderUnstyled.js#L384

Due to this call:
https://github.com/mui-org/material-ui/blob/2d4d0663ff1ed732e6952705d0e23eda13ae25ea/packages/material-ui-unstyled/src/SliderUnstyled/SliderUnstyled.js#L460

It seems to be related to the slider being unmounted while event callbacks related to the notch being dragged are still triggered, for example in a Tooltip:
https://codesandbox.io/s/unstyledslider-material-demo-forked-7yzjd?file=/demo.js
Screen Shot 2021-06-14 at 3 03 37 PM
I hold the notch, slide it three or four times, and suddenly move the cursor away while still holding the notch, forcing the tooltip to close, and after some tries, it throws the error:
Screen Shot 2021-06-14 at 3 04 09 PM

@eps1lon eps1lon added bug 🐛 Something doesn't work component: slider This is the name of the generic UI component, not the React module! labels Jun 16, 2021
@eps1lon
Copy link
Member

eps1lon commented Jun 16, 2021

Thanks for the report.

I added a screen recording to help understand the issue:

slider-getbounding-type-error.mp4

@AshuKV
Copy link

AshuKV commented Jun 19, 2021

I want to work on this issue. Please assign this issue to me.

@luminaxster
Copy link
Contributor Author

Any update?

@ertrzyiks
Copy link

ertrzyiks commented Sep 24, 2024

I also see this problem and from what I found in base-ui repo it has been fixed there in mui/base-ui#373

Specifically, before any operation happen on the slider the code checks for presence of the slider: https://github.com/mui/base-ui/blob/919782450f55281e2609aee375a252a50aa3d3d6/packages/mui-base/src/Slider/Root/useSliderRoot.ts#L315-L317

const { current: sliderControl } = controlRef;
if (!sliderControl) {
  return null;
}

const { width, height, bottom, left } = sliderControl!.getBoundingClientRect();

That extra check would prevent @mui/base from throwing the error.

@hafsalatif
Copy link

I also see this problem and from what I found in base-ui repo it has been fixed there in mui/base-ui#373

Specifically, before any operation happen on the slider the code checks for presence of the slider: https://github.com/mui/base-ui/blob/919782450f55281e2609aee375a252a50aa3d3d6/packages/mui-base/src/Slider/Root/useSliderRoot.ts#L315-L317

const { current: sliderControl } = controlRef;
if (!sliderControl) {
  return null;
}

const { width, height, bottom, left } = sliderControl!.getBoundingClientRect();

That extra check would prevent @mui/base from throwing the error.

I am using the latest version of all but still facing same issue

 "@emotion/react": "^11.11.4",
 "@emotion/styled": "^11.11.5",
 "@mui/icons-material": "^5.15.20",
 "@mui/lab": "^5.0.0-alpha.170",
 "@mui/material": "^5.15.20",

Screenshot from 2024-10-11 12-46-12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: slider This is the name of the generic UI component, not the React module!
Projects
None yet
Development

No branches or pull requests

5 participants