question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Port babel-plugin-styled-components to SWC

See original GitHub issue

This Babel plugin is the most used customization of .babelrc.

The plugin is split up in multiple separate transforms:

https://github.com/styled-components/babel-plugin-styled-components/blob/a26774e599c82c72e8793989f60310d29c181fac/src/index.js

The defaults are here: https://github.com/styled-components/babel-plugin-styled-components/blob/950692b92855f17609e4281d5081e3d2acbf4b6b/src/utils/options.js

The critical one which makes styled-components not have hydration issues with Next.js is displayNameAndId. All the other ones seem to be optimizations. Because of this I’d start by porting the displayNameAndId transform and then check what else can be ported.

Looking at the defaults the only transform that is disabled by default is the pure annotations one.

List of transforms:

  • ssr – enabled when styledComponents: true
  • displayName – enabled when styledComponents: true, disabled in production to reduce file size
  • css prop
  • fileName
  • minify
  • transpileTemplateLiterals
  • pure
  • namespace

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:197
  • Comments:48 (19 by maintainers)

github_iconTop GitHub Comments

19reactions
kritika-agrawal-dunzocommented, Feb 8, 2022

@timneutkens when are you planning to release support for css prop?

17reactions
timneutkenscommented, Nov 2, 2021

swc-project/swc#2506

Unclear if this is relevant, but it looks like SWC fixed the compiler to not break with styled-components. Still probably not enough to close this issue for customization/optionality, but maybe if updated, swc can compile SC at a base level now?

The linked issue is unrelated as that one is about the minifier. This issue is about implementing the transforms that are critical for running styled-components correctly when doing SSR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

swc/plugin-styled-components
SWC plugin for styled-components. Latest version: 1.5.33, last published: 5 days ago. Start using @swc/plugin-styled-components in your ...
Read more >
Advanced Features: Next.js Compiler
Styled Components. We're working to port babel-plugin-styled-components to the Next.js Compiler. First, update to the latest version of Next.js: npm install ...
Read more >
styled-components now usable with SWC in Next.js 12 ...
We've ported the critical option of babel-plugin-styled-components that prevents hydration mismatches to SWC. Learn more: ...
Read more >
Next failed to load SWC binary
Delete the package-lock.json file and the node_modules directory in your project and then run npm install on your terminal.
Read more >
Migrating your React app from Webpack to Vite
npm i --save-dev vite @vitejs/plugin-react vite-plugin-html ... For example, to add babel-plugin-styled-components plugin:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found