-
-
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
Slider doesn't work with frozen arrays #27347
Comments
It doesn't look like this bug report has enough info for one of us to reproduce it. Please provide a CodeSandbox (https://material-ui.com/r/issue-template-next), a link to a repository on GitHub, or provide a minimal code example that reproduces the problem. Here are some tips for providing a minimal example: https://stackoverflow.com/help/mcve |
sure, here is it: https://codesandbox.io/s/damp-glade-ld9m7?file=/src/Demo.tsx:134-148 |
Thanks for the report! Input parameters should be readonly. Object.freeze shows that this is currently not the case, which is a bug. |
I think the type checker is not strict enough.
@eps1lon as you said input params const isImmutable = (obj) =>
!Object.isExtensible(obj) || Object.isSealed(obj) || Object.isFrozen(obj);
const mutableArrayOf = function (innerTypes) {
function validate(props, propName, componentName) {
const arr = props[propName];
/**
* check array and inner elements here.
*/
PropTypes.checkPropTypes(
{ array: PropTypes.arrayOf(innerTypes) },
{ array: arr },
`prop`,
`${componentName}.${propName}`
);
/**
* check mutable here.
*/
if (isImmutable(arr)) {
return new Error(
`Invalid prop [${arr}] supplied to ${componentName}. Validation failed due to this is immutable.`
);
}
}
return validate;
};
Slider.propTypes = {
value: PropTypes.oneOfType([PropTypes.number,mutableArrayOf(PropTypes.number)]),
}; |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Fixed in #28472 |
Because of this perf optimization Slider doesn't work with frozen arrays:
https://github.com/mui-org/material-ui/blob/a3dbd6cc4e3f07df702a807ffb3f058586cff324/packages/material-ui-unstyled/src/SliderUnstyled/SliderUnstyled.js#L96
If I pass a frozen array as a
value
prop to the slider, it throws an error because it attempts to sort the result of thesetValueIndex
function, but it's impossible to sort the frozen array. Currently, I receive a frozen array from the Apollo. I can spread/slice manually, before passing to the Slider, but it feels dirty to do it. It's probably just better to drop this optimization - copying of such a small array is not expensiveThe text was updated successfully, but these errors were encountered: