mui / mui/material-ui

[styled-engine-sc] Unknown prop "sx" warning when using styled with styled-components v6

Open
#41,573 4 comments 0 reactions 1 assignee View on GitHub

@brijeshb42 is already working on this.

Since Mar 20, 2024.

package: styled-engine-sc scope: system
Dominant language
JavaScript
Stars
99.1k
Forks
32.5k
Avg merge
2d 17h
Merged PRs (30d)
106

Description

Steps to reproduce

Link to live example: https://codesandbox.io/p/sandbox/mui-styled-components-prop-forwarding-knft9v

Steps:

  1. Setup styles with styled-components (https://mui.com/material-ui/integrations/styled-components/)
  2. Use styled('div') from @mui/material/styles
  3. Add sx styles to the created component
  4. Warning in dev tool console & sx in rendered div
Current behavior

The given sx property isn't removed in the rendered div:

<div sx="[object Object]" class="sc-guDLey idRkGC">Styled div</div>
Expected behavior

In the styled documentation is written:
It adds by default the shouldForwardProp option (that can be overridden), taking into account: ownerState, theme, sx, and as.
Therefore I would expect the sx property to be removed from the rendered div.

Context

No response

Your environment

package.json

  • styled-components 6.1.8
  • @mui/styled-engine-sc 5.14.12
  • @mui/styles 5.15.14
  • @mui/material 5.15.14

System

  • Lates Chrome & MacOS version
  • yarn 4.1.0

Search keywords: sx warning, styled, styled-components

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.