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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

skipSx should update shouldForwardProps #31019

Open
2 tasks done
realamirhe opened this issue Feb 11, 2022 · 6 comments
Open
2 tasks done

skipSx should update shouldForwardProps #31019

realamirhe opened this issue Feb 11, 2022 · 6 comments
Labels
discussion package: system Specific to @mui/system

Comments

@realamirhe
Copy link

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary 馃挕

The skipSx doesn't work as expected when shouldForwardProp default mechanism is overwritten and does not include 'sx' directly

shouldForwardProp: (prop) => !["isEven"].includes(prop as string),
skipSx: true

This will send sx to the underlying component

Examples 馃寛

I made a code sandbox using the latest released material

https://codesandbox.io/s/goofy-phoebe-xc99x

Motivation 馃敠

making a custom component that only changes in CSS layer duo to props is a common practice
also, sx seems to be a little bit slow, and skipping it may gain some performance tips

so because we are working mostly with the Mui component and they pass the props to the underling dom node, it makes sense to have it as a core feature of the material


I seared on skipSx tags in the issue list and could not find an open issue, so posted a new one.

@realamirhe realamirhe added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Feb 11, 2022
@michaldudak
Copy link
Member

@mnajdova correct me if I'm wrong, but I think it works as it's supposed to. skipSx does not evaluate the sx prop in a component but does not control whether it's passed to the underlying components.
I can imagine a use case where you don't want to use the sx implementation provided by styled but still propagate the prop to the underlying component.

If you don't want to ignore the sx completely, set skipSx to true and add sx to the list of excluded props in shouldForwardProp.

@michaldudak michaldudak added discussion package: system Specific to @mui/system and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Feb 11, 2022
@realamirhe
Copy link
Author

Hi @michaldudak
My understanding was similarly the same, but there is an issue with this mindset

  shouldForwardProp: (prop) => !["isEven"].includes(prop as string),
  skipSx: true

this should not apply the sx but it does!
could you take a look at an example https://codesandbox.io/s/goofy-phoebe-xc99x

@michaldudak
Copy link
Member

This is expected. In this example the sx prop is not handled by the styled wrapper, but by Typography itself. Try wrapping a host component, such as <p> in styled (styled('p', {) instead of Typography to see that the sx prop has no effect if skipSx is set to true.

@realamirhe
Copy link
Author

That's okay, I know it prevents the sx to go deeper from the created component (styled one)
But I believe differences happen to exist because of our expectations of shouldForwardProp and skipSx priority, for me skipSx is more prior to shouldForwardProps, and vice versa

Anyway, I post it as a feature request, not a bug, and the discussion was exactly what I was looking for.

@mnajdova
Copy link
Member

mnajdova commented Mar 2, 2022

After reading trough it I think it makes sense for the skipSx prop to determine whether to forward the sx prop or not. I think we should combine this logic with the default shouldForwardProp. But, if a custom shouldForwardProp function is specified, it should be a responsibility of the developer to decide on it. I am not sure if this is very intuitive.

@michaldudak
Copy link
Member

It would be a breaking change, though, so we could think about it for the v6 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion package: system Specific to @mui/system
Projects
Status: Backlog
Development

No branches or pull requests

5 participants