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

Variable expansions for media queries inside styled-jsx break with Turbopack #61788

Closed
miselin opened this issue Feb 7, 2024 · 4 comments · Fixed by #61662 or #61976
Closed

Variable expansions for media queries inside styled-jsx break with Turbopack #61788

miselin opened this issue Feb 7, 2024 · 4 comments · Fixed by #61662 or #61976
Assignees
Labels
bug Issue was opened via the bug report template. linear: turbopack Confirmed issue that is tracked by the Turbopack team. locked Turbopack Related to Turbopack with Next.js.

Comments

@miselin
Copy link

miselin commented Feb 7, 2024

Link to the code that reproduces this issue

https://github.com/miselin/next-style-jsx-var-expansion-repro

To Reproduce

  1. Run npm run dev
  2. Visit http://localhost:3000
  3. The page should build without error, showing "Hello" text that changes size based on the browser window dimensions (i.e. the media query is using the variable-expanded 768px breakpoint correctly)
  4. Terminate that process
  5. Run npm run dev:turbo
  6. Visit http://localhost:3000
  7. You'll see a syntax error exception:
./pages/index.tsx:8:19
Parsing ecmascript source code failed
   6 |     <div>
   7 |       <h1 className="header">Hello</h1>
>  8 |       <style jsx>{`
     |                   ^
>  9 |         .header { font-size: 48px; }
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 10 |
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 11 |         @media screen and (max-width: ${MOBILE_MAX}px) {
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 12 |           .header { font-size: 12px; }
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 13 |         }
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 14 |       `}</style>
     | ^^^^^^^^
  15 |     </div>
  16 |   );
  17 | }

Error while processing css: failed to parse css using lightningcss: Invalid media query at :0:112.

Current vs. Expected behavior

Expected: I see the expected variable expansion and correct media query CSS, allowing the use of constants for controlling media query breakpoints in an application.

Current: enabling Turbopack instead triggers an exception during page build unless the variables are removed.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 22.6.0: Thu Nov  2 07:43:57 PDT 2023; root:xnu-8796.141.3.701.17~6/RELEASE_ARM64_T6000
Binaries:
  Node: 20.10.0
  npm: 10.2.3
  Yarn: N/A
  pnpm: 8.11.0
Relevant Packages:
  next: 14.1.1-canary.42 // Latest available version is detected (14.1.1-canary.42).
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.1.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Turbopack (--turbo)

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

This does not repro with Next 14.1.0. The first version that repros this issue is 14.1.1-canary.9, canary versions earlier than that work as expected.

PACK-2446

@miselin miselin added the bug Issue was opened via the bug report template. label Feb 7, 2024
@github-actions github-actions bot added the Turbopack Related to Turbopack with Next.js. label Feb 7, 2024
@ForsakenHarmony ForsakenHarmony added the linear: turbopack Confirmed issue that is tracked by the Turbopack team. label Feb 8, 2024
@kdy1
Copy link
Member

kdy1 commented Feb 13, 2024

swc-project/plugins#267 will fix the issue

@kdy1 kdy1 self-assigned this Feb 13, 2024
kdy1 added a commit that referenced this issue Feb 13, 2024
# Turbopack changes

* vercel/turborepo#7342 <!-- OJ Kwon - docs(turbopack): build, deploy rustdocs -->
* vercel/turborepo#7356 <!-- OJ Kwon - ci(workflow): remove doc deploy -->
* vercel/turborepo#7272 <!-- Donny/강동윤 - build: Update `swc_core` to `v0.90.7` -->


### What?

Update swc crates

### Why?

- To apply swc-project/swc#8532 and other bugfixes

### How?

 - Closes PACK-2389
 - Closes PACK-2446
 - Closes #61788
@kdy1
Copy link
Member

kdy1 commented Feb 13, 2024

Re-opening as swc-project/plugins#267 is not applied by #61662.
I forgot bumping the version of styled-jsx crate so it's not merged

@kdy1 kdy1 reopened this Feb 13, 2024
kdy1 added a commit that referenced this issue Feb 14, 2024
### What?

Update swc crates one more time.

### Why?

To apply swc-project/plugins#267

### How?

Fixes #61788

Closes PACK-2446
Closes PACK-2476
@miselin
Copy link
Author

miselin commented Feb 15, 2024

I'm still seeing this repro on Next.js 14.1.1-canary.55 (turbo) (it looks like canary.53 included the swc_core version bump).

Is that expected, is there a later release that will fix this?

Copy link
Contributor

github-actions bot commented Mar 1, 2024

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot added the locked label Mar 1, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. linear: turbopack Confirmed issue that is tracked by the Turbopack team. locked Turbopack Related to Turbopack with Next.js.
Projects
None yet
3 participants