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.

Nextjs does not render styles on the server (client only) when used within a monorepo that has mixed versions of styled-jsx

See original GitHub issue

What version of Next.js are you using?

12.0.7

What version of Node.js are you using?

14.18.1

What browser are you using?

chrome

What operating system are you using?

mac0s

How are you deploying your application?

vercel

Describe the Bug

styled-jsx does not render styles server side when there are multiple versions of itself within a monorepo.

This is directly related to https://github.com/vercel/styled-jsx/issues/751. I am bringing it up here because I suspect there is something else going on besides node module resolution causing this bug – is it possible that the nextjs webpack config is grabbing the wrong version of styled-jsx at compile time?

Video

Before: Styling works because JS is enabled. After: JS is disabled so styling does not work. recording

Expected Behavior

I expect the styling to be rendered on the server, not the client.

To Reproduce

  1. Clone @Regaddi’s repo: https://github.com/Regaddi/yarn-next-styled-jsx-fouc
  2. run yarn install
  3. run cd /packages/example/
  4. yarn run dev
  5. In chrome, open dev tools and click the little cog icon at the top right.
  6. Disable Javascript and do not close the dev tools window.
  7. Refresh page.
  8. Observe no styles rendered.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
scott-coatescommented, Dec 28, 2021

Update:

It looks like webpack is doing its thing with styled-jsx and pulling it somehow. If you view yarn-next-styled-jsx-fouc/node_modules/next/node_modules/styled-jsx/dist/webpack.js in the example repo, you’ll see


  var commentType = content.match(/\/*\s*@styled-jsx=(scoped|global|resolve)/);

  if (commentType) {
    options.type = commentType[1];
  }

  var output = "import css from 'styled-jsx/css';\n\nconst styles = css";

So it looks like webpack is doing some static stuff with styled-jsx and pulls in that depdendency via this pattern (scoped|global|resolve). I don’t really know what’s going on here but it’s progress 🤷‍♂️

0reactions
github-actions[bot]commented, Sep 30, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Server-side rendered styled-components with Nextjs
js comes configured with styled-jsx . But what if you want to use something else for styling? I've recently worked on setting up...
Read more >
Basic Features: ESLint - Next.js
Next.js provides an integrated ESLint experience by default. These conformance rules help you use Next.js in the optimal way.
Read more >
Styles not applying on first client render (nor after) when ...
I would expect the server to send back the html/styles for the server based version of the component, and then following the first...
Read more >
What's new in Next.js 13, and what do they really do?
A practical guide to Next.js 13. How real-world code and architecture need to adapt to Server Components, Streaming SSR, Layouts, and Turbopack.
Read more >
Storybook Addon Next
A no config Storybook addon that makes Next.js features just work in ... If you feel that you have a good use case,...
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