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

NextJS & SSR Bug: Warning: Prop className did not match. Server: "css-1ignaq9" Client: "css-1xh7umy" #684

Closed
adventurini opened this issue May 7, 2020 · 10 comments
Labels
Topic: Color Mode 🌓 Issue or PR related to color mode Topic: SSR 💻 Issue or PR related to Server side rendering (Next.js or Gatsby) Type: Bug 🐛 Something isn't working

Comments

@adventurini
Copy link

Describe the bug
Console error on load.
Screen Shot 2020-05-07 at 9 39 56 AM

Expected Behavior
No console error on load.

@benregn
Copy link

benregn commented May 14, 2020

@adventurini I think people will have a hard time helping you out unless you provide some more details about this problem and ideally minimal project reproducing the bug.

One question, are you using the ColorModeProvider? Server-side might be rendering the light theme and when it's rendered and hydrated on the client, it might change to the dark theme which uses different classes.

@feross
Copy link
Contributor

feross commented May 14, 2020

I've also seen this issue when using ColorModeProvider. Removing it fixes the issue.

@benregn What's the right way to handle the case where the server sends a light mode page but the client is in dark mode?

@with-heart
Copy link
Contributor

I haven't had time to go through and give it the read it deserves, but Josh W. Comeau recently took a deep dive on this exact topic: https://joshwcomeau.com/gatsby/dark-mode/

Might be useful information in there. I'll try to go through it later and report back any relevant findings.

@with-heart with-heart added Topic: SSR 💻 Issue or PR related to Server side rendering (Next.js or Gatsby) Type: Bug 🐛 Something isn't working Topic: Color Mode 🌓 Issue or PR related to color mode labels May 14, 2020
@benregn
Copy link

benregn commented May 14, 2020

Josh's article is great and explains the underlying problems really well. His solution relies on using CSS Custom Properties (Variables) so if you aren't using them or aren't familiar with them, it could take a bit of work to setup. I haven't experimented with his solution yet when using Chakra.

@feross I'm not sure if I can answer what the 'right way' is but the solution Josh presents definitely works and another solution I've seen work is to store the preference in a cookie but that does break static optimization.

@segunadebayo
Copy link
Member

Hey guys,

We're fixed the issue with the ColorModeProvider in the next release.

It'll be landing soon!

@feross
Copy link
Contributor

feross commented Jul 17, 2020

👏 @segunadebayo

@javierfuentesm
Copy link

I still have this issue
image

@turtletongue
Copy link

turtletongue commented Feb 23, 2021

I still have this issue
image

same
bandicam 2021-02-23 15-04-38-330

@ADParris
Copy link

ADParris commented Jun 25, 2021

Just an F.Y.I. that 'useMediaQuery' is still causing this issue. Presumably because Chakra rebuilds the CSS when it hits the front end and thus the two do not match. I did manage to resolve this little conflict rather easily, once I figured it out. I just moved the media queries to my global CSS, in my custom Chakra Theme, and removed any mention of 'useMediaQuery'. Boom! No error and no inconsistencies on re-render. Just thought I'd share for anyone else that happens along here with this little problem. 😉

@niconiahi
Copy link

niconiahi commented Jul 2, 2021

same happening to me when ussing useMediaQuery as so:

const useDevice = () => {
  const [isLargeDevice] = useMediaQuery('(min-width: 62em)')

  return {
    isLargeDevice,
  }
}

then used: (THIS THROWS AN ERROR)

  import { useDevice } from './useDevice'
  
  const { isLargeDevice } = useDevice()
  
   <Text color='white' textStyle={isLargeDevice ? 'body.bold.lg' : 'body.bold.md'}>
       Don't miss out on new proposals
   </Text>

used: (THIS DOESN'T)

   <Text color='white'>
       Don't miss out on new proposals
   </Text>

screenshot here:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Topic: Color Mode 🌓 Issue or PR related to color mode Topic: SSR 💻 Issue or PR related to Server side rendering (Next.js or Gatsby) Type: Bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants