[material-ui] Avoid ownerState
silent propagation
#42184
Labels
package: material-ui
Specific to @mui/material
ownerState
silent propagation
#42184
Following-up on #42062 (comment)
Problem
With the standardization of the slots pattern, we've run into this multiple times:
ownerState
, let's call itownerStateParent
ownerState
, let's call itownerStateChild
, that it needs to provide to its own childrenThe
ownerStateParent
is provided to the child slot component, as it's useful when overriding.But the child needs to take care of two things:
ownerStateParent
, coming through props, doesn't override its ownownerStateChild
when passing it to its own children. This is the reason for the change on lines 118-123:ownerState={ownerState}
must come after{...other}
.ownerStateParent
is not nested inside its ownownerStateChild
, otherwise, it would overrideownerStateChild
because of howcreateStyled
merges props (reference). This could cause bugs when accessing theownerState
in style variants props matching. Like it's done in this component (line 68). This is the reason fordelete ownerState.ownerState
on this file.The pattern of spreading
other
into the root component, as well as spreadingprops
intoownerState
, is spread throughout the codebase, and that's why we've been bumping into this repeatedly. This behavior is error-prone, as it's not evident unless you're familiar with the codebase.Ideas
other
and/orprops
without propagating unwantedownerState
s.useSlot
hook. The problem with this one is that most components would need to useuseSlot
.Search keywords:
The text was updated successfully, but these errors were encountered: