next.js icon indicating copy to clipboard operation
next.js copied to clipboard

Warning: Prop className did not match.

Open th0th opened this issue 7 years ago • 273 comments

Examples bug report

Example name

with-styled-components

Describe the bug

Also posted here: #2538

Using css prop introduced with styled-components v4 causes Warning: Prop className did not match..

To Reproduce

Add any HTML element with css prop.

Expected behavior

Correctly styled rendering on the server side without any warnings.

Screenshots

57497472-7b657c00-72e0-11e9-84c5-e7e5fa0d351c

System information

  • OS: Windows
  • Chrome
  • Version of Next.js: 8.1.0

Additional context

Here is an example I created to demonstrate the issue: https://codesandbox.io/embed/jlwvwyy0ow

Open this and refresh once the building is done: https://jlwvwyy0ow.sse.codesandbox.io/

th0th avatar May 13 '19 15:05 th0th

Happens to me everytime. +1

kumarabhirup avatar May 13 '19 15:05 kumarabhirup

The same happens with Next v.7. This error doesn't occur when the server starts, only after making changes in the code.

Tomekmularczyk avatar May 19 '19 17:05 Tomekmularczyk

I'm seeing the same error. It doesn't appear to affect the live app, but it's very annoying to have it constantly appearing locally.

elliotbonneville avatar May 23 '19 20:05 elliotbonneville

I have a similar error, but with inline style.

Warning: Prop `style` did not match. Server: "height:50px;margin-left:4vw;cursor:pointer;width:auto;margin-top:0px" Client: "height:30px;margin-left:4vw;cursor:pointer;width:auto;margin-top:6px"

😢

ghost avatar May 24 '19 14:05 ghost

I hope once enough people raise their voices here this issue will get attention 🙂

th0th avatar May 24 '19 17:05 th0th

I face this issue in my simple navbar active className, is there a workaround until official fix?

SarKurd avatar May 26 '19 05:05 SarKurd

Use 👍 on the initial issue instead of "+1" and "same problem".

If you do feel like posting +1 provide a clear and concise reproduction that is clearly reproducible. Otherwise the comment is not actionable.

This goes for any open-source project you're commenting on.

Thanks 🙏

timneutkens avatar May 27 '19 13:05 timneutkens

Seems like they fixed latest release this bug https://github.com/styled-components/styled-components/issues/2563

c0b41 avatar May 31 '19 15:05 c0b41

Nope, that's a totally different log message, it is the one with yellow background on the screenshot I posted, it disappeared after the update.

First one, warning about different classNames is still there.

th0th avatar May 31 '19 15:05 th0th

Tagging this as up for grabs to investigate by a motivated contributor.

Timer avatar Jun 14 '19 15:06 Timer

Hey there, please update babel-plugin-styled-components to the latest version which should fix css prop mismatches: https://github.com/styled-components/babel-plugin-styled-components/releases/tag/v1.10.1

I've noticed an error message in development still, but no ill effects from it so can be safely ignored.

quantizor avatar Jun 16 '19 16:06 quantizor

Still same after fix posted above, and can't ignore it. Having some layout problems when this error occurs.

ThisIsEsh avatar Jun 20 '19 07:06 ThisIsEsh

So do I, when this occurs I'm getting layout errors and my component go into a weird state where they do not render based on new props.

It happens for me in an inline style.

ShayDavidson avatar Jul 03 '19 17:07 ShayDavidson

Make sure your babel plugin version is up to date, lots of fixes in the last couple weeks. We also made changes to how we do dev styles in v5 that largely address this issue

quantizor avatar Jul 03 '19 17:07 quantizor

The Prop 'style' does not match is not solved with the babel plugin upgrade.

ShayDavidson avatar Jul 03 '19 18:07 ShayDavidson

"style" is an inline style and nothing to do with styled-components, so that's a totally separate issue

quantizor avatar Jul 03 '19 18:07 quantizor

what's the fix for this one? i always get this warning everytime i refresh. i always do refresh everytime change something, bad old habit 😅 everytime i do refresh it shows warning and the styling all gone

jass-trix avatar Jul 03 '19 18:07 jass-trix

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 side rendered style client generates it by itself.

edit: I just downloaded the example and couldn't reproduce the issue while using the same code as in your codepen sandbox. Tested in chrome and firefox and it behaves the same (no error nor warning).

masives avatar Jul 08 '19 11:07 masives

@jass-trix have you tried the s-c v5 beta? We made a lot of changes to eliminate this issue.

quantizor avatar Jul 08 '19 22:07 quantizor

@probablyup how to use this version?

jass-trix avatar Jul 09 '19 02:07 jass-trix