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.

Next.js Prop `className` did not match.

See original GitHub issue

Describe the bug I received this error in my browser console in a Next.js application.

Warning: Prop className did not match. Server: “css-1jvcsfd-Test” Client: “css-0”

(Components with some actual styles in sx will still lack their component name after their class names, like the following:)

Warning: Prop className did not match. Server: “css-wboa0q-Test2” Client: “css-1qb7fb8”

I have read from the Rebass docs, that Emotion works out of the box and does not require additional configuration for SSR. What am I doing wrong?

The components seems to have rendered correctly for all the ThemeUI JSX files I’ve used sx attributes on. None of them have their component names in their class names.

To Reproduce I have the following files:

components/Test.jsx

/** @jsx jsx */
import { jsx } from 'theme-ui'

const Test = () => (<div sx={{}}/>)

export default Test

pages/index.jsx

import React from 'react'
import Test from '../components/Test'

const index = () => (
  <Test/>
)

export default index

.babelrc

{
  "presets": [
    "next/babel"
  ]
}

I have the same _app.jsx and _document.jsx as the one in the next example folder. I have not used the withMDX() function in next.config.js

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
Andaristcommented, Jan 11, 2020

A little correction - we might release this to production soon, need to wait for Mitchell’s opinion first though

1reaction
danvimcommented, Jan 11, 2020

@jxnblk https://github.com/emotion-js/emotion/issues/1462#issuecomment-573073340 Referring to this comment of mine, the problem is due to the Theme UI’s jsx wrapper function, which failed the original regex.

From Theme UI’s dist/index.esm.js:

var jsx$1 = function jsx$$1(type, props) {
  var arguments$1 = arguments;

  for (var _len = arguments.length, children = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
    children[_key - 2] = arguments$1[_key];
  }

  return jsx.apply(undefined, [type, parseProps(props)].concat(children));
};

By cross-checking my stack trace over on that issue, it would seem the regex for matching the component name failed to expect some other function (Theme UI’s wrapper) would use the 2nd line.

@Andarist said it’s an oversight in Emotion’s code base, but a fix wouldn’t be issued anytime soon on production. This probably affects all Firefox versions.

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
The same happens with Next v.7. This error doesn't occur when the server starts, only after making changes in the code.
Read more >
Fixing ClassName did not match error - DEV Community ‍ ‍
babelrc in the root directory and configure it. Here's the config file. Restart your server and refresh your server and you should be...
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 >
Prop `className` did not match - CodeSandbox
mikestopcontinuesmikestopcontinues. Templateelegant-franklin-htp7v; Environmentnext. Files. pages. _document.js. index.js .babelrc .gitignore. README.md.
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