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.

Prop `className` did not match. Server: "sc-kEYyzF gfWKdx" Client: "sc-ifAKCX cFlEyZ"

See original GitHub issue

Environment

next: 6.1.1 babel-plugin-styled-components: 1.8.0 styled-components: 3.3.3

.babelrc

{
  "presets": [
    "next/babel"
  ],
  "plugins": [
    [
      "babel-plugin-styled-components",
      {
        "ssr": true,
        "displayName": true,
        "preprocess": false
      }
    ]
  ]
}

Expected Behavior

Server and Client style has to be the same

Actual Behavior

The server-side generates the right style. However, the client-side broke down the UI.

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
probablyupcommented, Oct 24, 2018

If they’re different with the babel plugin on and ssr mode enabled, your code likely has different behavior on the server vs client. In general, it’s best to put client-specific enhancements in componentDidMount rather than at construction time so rehydration is not affected.

Some code smells to search for: typeof window !== 'undefined', if (process.browser)

2reactions
davidnguyen11commented, Oct 26, 2018

The library I used the create-react-app to develop and then published it, I run script to compile from ES6 => ES5.

Then in the main site, I used next.js and install the library. The issue happens there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Warning: Prop `className` did not match. when using styled ...
That error is showing you the class that is being created by your styled-components library on the server and how it is different...
Read more >
Warning: Prop className did not match. #7322 - GitHub
It appears to be an issue that backend generates styled component but client doesn't get it/doesn't use it and instead of using server...
Read more >
Fixing ClassName did not match error - DEV Community ‍ ‍
Create a file named .babelrc in the root directory and configure it. Here's the config file. { "presets": [ "next/babel" ], "plugins": ...
Read more >
Solving the Styled Components Warning in Next.JS with Babel
Warning: Prop `className` did not match. Server: “fs-fdsf” Client: “sd-dfasj”. The combination of Next.JS and Styled Components is truly ...
Read more >
Warning: Prop className did not match | By Arbaoui mehdi
Prop className did not match " which caused mainly by a styling is being rendered on the client dynamically and the "./pages/_app.js" was ......
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