styled-components' `css` prop not working via SWC transform
See original GitHub issueVerify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System: Platform: darwin Arch: x64 Version: Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:xnu-8020.121.3~4/RELEASE_X86_64 Binaries: Node: 14.19.3 npm: 6.14.17 Yarn: 1.22.19 pnpm: N/A Relevant packages: next: 12.1.6 react: 17.0.2 react-dom: 17.0.2
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
The styled-components transform for SWC isn’t working as expected when using the css
prop to add styles.
Instead of applying the styles a css
HTML attribute is added to the element.
Expected Behavior
When using the css
prop in JSX I expect the styled to be applied to the rendered HTML instead of the value being passed as a prop and rendered as an HTML attribute.
Link to reproduction
https://codesandbox.io/s/next-12-styled-components-transform-bug-t53kxi
To Reproduce
In the CodeSandbox I have two styled components that set a different text color. Then I have two tags where I set different colors but via the css
prop.
The styles added via the css
prop are not applied.
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:5
Top GitHub Comments
Second this!
NB: It seems that this only happens when using strings and not template strings (truly hope I’m wrong because this should not make any difference unless some transpiling magic), at least, in my project that seems to be correlated.
Forking the codesandbox, I see the following behaviour.
Initial load of the page, works!
Making a change to the
css=""
element, live reload recompiles, color does not update:Making a change to the
css={``}
element, live reload recompiles, color updates:Reloading the page, both changes apply correctly:
https://codesandbox.io/s/next-12-styled-components-transform-bug-forked-mt35lq?file=/pages/index.js:280-286
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.