next.js icon indicating copy to clipboard operation
next.js copied to clipboard

<style jsx> cannot render in next/head

Open Capricair opened this issue 3 years ago • 4 comments

Verify canary release

  • [X] I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
Binaries:
  Node: 16.16.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant packages:
  next: 12.3.2-canary.26
  eslint-config-next: 12.1.0
  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

cannot render in next/head
<Head>
  ...
  <style jsx>{`
    body {
      margin: 0;
      background: #ccc;
    }
  `}</style>
</Head>

Expected Behavior

render in next/head successfully

Link to reproduction

https://github.com/Capricair/next-dynamic-issue

To Reproduce

  1. npm run install
  2. npm run dev
  3. open homepage

Capricair avatar Oct 13 '22 08:10 Capricair

Have you tried the global flag on the style tag?

chriseagle avatar Oct 21 '22 16:10 chriseagle

If you just want to add a style tag in Next/Head, you can just remove jsx prop. If you want to add jsx style globally, you need to move this style tag out of Head component, do something like this: https://nextjs.org/blog/styling-next-with-styled-jsx (you can also refer to here: https://github.com/vercel/styled-jsx) But I cannot find the reason why jsx style tag be omitted in Head component. Not sure if anyone can point out that.

teobler avatar Oct 24 '22 06:10 teobler

If you just want to add a style tag in Next/Head, you can just remove jsx prop. If you want to add jsx style globally, you need to move this style tag out of Head component, do something like this: https://nextjs.org/blog/styling-next-with-styled-jsx (you can also refer to here: https://github.com/vercel/styled-jsx) But I cannot find the reason why jsx style tag be omitted in Head component. Not sure if anyone can point out that.

Next.js includes Styled JSX by default

Capricair avatar Nov 07 '22 10:11 Capricair

Have you tried the global flag on the style tag?

global flag also doesn't work

Capricair avatar Nov 07 '22 10:11 Capricair