Warning because of dynamic values during SSR
See original GitHub issueDescribe 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:
- Created 4 years ago
- Reactions:11
- Comments:24 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.@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 tocreateUseStyles
, the warnings are emitted just the same.You can download my repo, install dependencies, and run
npm run dev
to try it out yourselves.