-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Forward .defaultProps when reusing __emotion_base #659
Conversation
I've looked into the code and it seems to me that for return tag.__emotion_real.withComponent(tag.__emotion_base, options) to fix |
I think for shouldForwardProp we could set it as a static property on let shouldForwardProp to let shouldForwardProp = tag.__emotion_shouldForwardProp so it uses the shouldForwardProp on the component that's passed in if it exists and passing a shouldForwardProp with a styled component that already has a shouldForwardProp will override the original shouldForwardProp. For defaultProps, I think the only way to solve all the edge cases for it would be to opt out of the component flattening if defaultProps is defined since this solution wouldn't account for setting defaultProps on a styled component, passing it to styled again and setting defaultProps on that component as well. |
Problem with that approach is that we have to think about it & add those static properties whenever we introduce any new option. Could you explain in short (or link me to some resources) on how exactly staticClassName, identifierName, stableClassName are used? Do they suffer from the same problem? Or they simply shouldn't get forwarded?
Developer can (although it's a little bit quirky) extend |
We don't do component flattening with
const SomeComponent = styled.div`
color: hotpink;
`
const AnotherComponent = styled(SomeComponent)`
color: green;
`
render(
<div
css={css`
${SomeComponent} {
color: darkcyan;
}
`}
>
<AnotherComponent />
</div>
) |
Thanks for the explanation. The only thing I'm worrying about is that in the future we might want to "passthrough" more options and static properties approach doesnt scale that well. Also as to As to |
Codecov Report
|
I think that using something that doesn't scale well for options is good since it encourages us to not add options because adding options means users have to learn more specifics about the API and IMO that's not something we want. For reusing const SomeComponent = styled('div', {
shouldForwardProp: prop => {
switch (prop) {
case 'someProp':
return false
default:
return true
}
}
})`
color: hotpink;
`
const AnotherComponent = styled(SomeComponent, {
shouldForwardProp: prop => {
return true
}
})`
background-color: green;
` I'm just gonna merge this as is because the edge case I presented is going to be ridiculously rare so if someone opens an issue about it then let's fix it but right now, let's leave it like this. |
I've proposed it working like As you have mentioned it doesnt make sense to forward If we just replace |
fixes #654
I feel though that we should figure out more holistic approach as
.defaultProps
is only part of the problem - any other config (i.e.shouldForwardProp
) will get lost too when reusing__emotion_base
. This should act like.withComponent
in this regard.Thoughts?