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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

styled-jsx issue with interpolation when SWC is enabled #30799

Closed
timneutkens opened this issue Nov 2, 2021 · 1 comment · Fixed by #30928
Closed

styled-jsx issue with interpolation when SWC is enabled #30799

timneutkens opened this issue Nov 2, 2021 · 1 comment · Fixed by #30928
Assignees
Labels
SWC Related to minification/transpilation in Next.js.
Milestone

Comments

@timneutkens
Copy link
Member

timneutkens commented Nov 2, 2021

Report: https://vercel.slack.com/archives/C0290CZ3U6Q/p1635502416198300?thread_ts=1635325628.111200&cid=C0290CZ3U6Q

@delbaoliveira investigated it:

Hey @timneutkens So I narrowed their issue down. They are using an integer as a variable when combining the https://github.com/vercel/styled-jsx#dynamic-styles and https://github.com/vercel/styled-jsx#external-css-and-styles-outside-of-the-component styled-jsx features.

const paddingInt = 10
const paddingStr = "10"

// ✅ babel
// ❌ swc
const Test1 = () => (
 <div>
  <p>test 1</p>
  <style jsx>{styles1}</style>
 </div>
)

const styles1 = css`
 p {
  color: red;
 }

 .something-else {
  padding: ${paddingInt}px;
 }
`
  • Using an integer variable works with Babel but doesn't work in SWC
  • Using a string as a variable works in both Babel and SWC
const paddingInt = 10

// ✅ babel
// ✅ swc
const Test2 = () => (
 <div>
  <p>test 2</p>
  <style jsx>{`
   p {
    color: red;
   }
   .something-else {
    padding: ${paddingInt}px;
   }
  `}</style>
 </div>
)
  • Using an integer in an inline style worked in both Babel and SWC
import { paddingStrExternal } from "../lib/external"

// ✅ babel
// ❌ swc
const Test7 = () => (
 <div>
  <p>test 7</p>
  <style jsx>{styles7}</style>
 </div>
)

const styles7 = css`
 p {
  color: red;
 }
 .something-else {
  padding: ${paddingStrExternal}px;
 }
`
  • Importing a string variable from another file did not work in SWC, but worked in Babel.

I also tested a few different variations like css.resolve which worked in both.

@timneutkens timneutkens added kind: bug SWC Related to minification/transpilation in Next.js. labels Nov 2, 2021
@timneutkens timneutkens added this to the 12.0.x milestone Nov 2, 2021
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
SWC Related to minification/transpilation in Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants