Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

SWC + styled-components: element classes & style classes are not synched #35989

Closed
1 task done
tremppu opened this issue Apr 8, 2022 · 2 comments
Closed
1 task done
Labels
bug Issue was opened via the bug report template. good first issue Easy to fix issues, good for newcomers

Comments

@tremppu
Copy link

tremppu commented Apr 8, 2022

Verify canary release

  • I verified that the issue exists in Next.js canary release

Provide environment information

Operating System:
Platform: win32
Arch: x64
Version: Windows 10 Pro
Binaries:
Node: 16.14.1
npm: N/A
Yarn: N/A
pnpm: N/A
Relevant packages:
next: 12.1.5-canary.4
react: 17.0.2
react-dom: 17.0.2
styled-components: 5.3.5

What browser are you using? (if relevant)

Chrome 100.0.4896.75

How are you deploying your application? (if relevant)

No response

Describe the Bug

Sometimes when passing props to styled-components component, the generated CSS class is not synched with the styles. Classes work normally when adding the basic .babelrc configuration for styled-components so I assume the problem is with SWC.

Expected Behavior

So far there has been 2 cases when classes are wrong:

  1. When starting the app, initial class is wrong but works after dynamically updating props. In this case the initial class should work without dynamic changes.
  2. After dynamically changing props the class changes on the element but CSS styles are scoped for the old class and if the props are changed to the original state, a third class is generated (kind like x -> y -> z -> y -> z). in this case the styles should be updated to the new class.

To Reproduce

I created a CodeSandbox version: https://codesandbox.io/s/next-styled-components-class-names-issue-bz5p0z?file=/pages/index.js

@tremppu tremppu added the bug Issue was opened via the bug report template. label Apr 8, 2022
@tremppu
Copy link
Author

tremppu commented Apr 8, 2022

Ok it seem that adding the: compiler: { styledComponents: true } to next.config.js solves the issue. Still since styled-components "works" without that I find that it would be great if there would be an automatic detection and a warning if that part is missing from next.config.js when styled-components is used without .babelrc.

@jankaifer
Copy link
Contributor

I'll convert this to a discussion.
But we would love to review a PR for this.

@jankaifer jankaifer added the good first issue Easy to fix issues, good for newcomers label Jan 13, 2023
@vercel vercel locked and limited conversation to collaborators Jan 13, 2023
@jankaifer jankaifer converted this issue into discussion #44854 Jan 13, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
bug Issue was opened via the bug report template. good first issue Easy to fix issues, good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants
@tremppu @jankaifer and others