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.

Warning because of dynamic values during SSR

See original GitHub issue

Describe the bug: I’m using my styles like these:

export default (theme) => ({
    root: {
        position: 'relative',
        display: 'inline-flex',
        alignItems: 'center',
        textAlign: 'center',
        background: theme.bgColor,
        fontWeight: ({weight}) => weight, // here is the problem
    },
});

And I’m getting this error on server-side (client is fine): Warning: [JSS] Rule is not linked. Missing sheet option "link: true". If I delete the dynamic value for fontWeight I will not get this error again. The problem not only in the warning itself, but also in the way how my styles will be applyed in production mode (they break styles in the styles where I’m using dynamic value and server sends me wrong styles after page reloading). P.S. I have tried using styles like this const useStyles = createUseStyles(styles, {link: true}); and it’s still not working 😦

Codesandbox link: I’m sorry, I have a problem with adding codesandbox.io with SSR and node.js console.

  • latest version:
  • Chrome:
  • Windows:

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:11
  • Comments:24 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
leedavidcscommented, Aug 20, 2020

@dipesh429 Short answer: No

Long answer: From what I’ve seen, the warnings seem not to impact styling, but I’ve decided to try and avoid using dynamic styles as much as possible regardless to be safe.

Just toggling between different classes using the clsx module and using the style prop works well enough in most spots where dynamic styles are desired. If you are on nextjs and are using this strategy, either using the built-in sass-module support or Linaria might be a better route for you.

4reactions
leedavidcscommented, Mar 4, 2020

@kof @m4theushw @SilverDY I’m actually experiencing this issue as well on NextJS.

I’ve produced a minimal example here.

What I’ve naively identified, is that the page emits these errors when there are multiple components on 1 page that renders dynamic styles.

Even when I supplied { link: true } as a second parameter to createUseStyles, the warnings are emitted just the same.

You can download my repo, install dependencies, and run npm run dev to try it out yourselves.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Logging and error management best practices in SSR apps
Handle errors and log them gracefully in your next web app with these best practice guidelines with examples using Next.js and Nuxt.js.
Read more >
The Perils of Rehydration - Josh W Comeau
A surprisingly-common misconception can lead to big rendering issues that are difficult to debug. This deep-dive tutorial examines how React ...
Read more >
Warning: Text content did not match. Server: "I'm out" Client
The hydration issue occurs because the HTML rendered on the browser doesn't match the one generated on the server. In your case this...
Read more >
React Hooks & SSR - ahooks 3.0
SSR is to run React code in a node environment, while global properties such as window, document, and navigator are not available at...
Read more >
Understand Next.js's incremental static regeneration against ...
SSR by default is often slower than SPA and SSG. Also, more API calls are required because the page HTML is generated in...
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