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: Warning `prop` className did not match. Server: "generated_server_className" Client: "generated_client_className"

See original GitHub issue

Describe the bug

After next.js compiles it throws a runtime error with something along the lines of:

Warning: Prop `className` did not match. Server: "pages_themeClass__sryalf0" Client: "pages__createTheme__sryalf0"

Link to reproduction

I have a fork of next.js that has an example of vanilla-extract with typescript and javascript

System Info

Output of npx envinfo --system --npmPackages @vanilla-extract/css,@vanilla-extract/webpack-plugin,@vanilla-extract/esbuild-plugin,@vanilla-extract/vite-plugin,@vanilla-extract/sprinkles,webpack,esbuild,vite --binaries --browsers:

  System:
    OS: Linux 5.14 Arch Linux
    CPU: (4) x64 AMD A8-7600 Radeon R7, 10 Compute Cores 4C+6G
    Memory: 341.82 MB / 6.74 GB
    Container: Yes
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.6 - ~/.local/share/volta/tools/image/node/14.17.6/bin/node
    npm: 6.14.15 - ~/.local/share/volta/tools/image/node/14.17.6/bin/npm
  Browsers:
    Brave Browser: 93.1.29.81
  npmPackages:
    @vanilla-extract/css: ^1.6.0 => 1.6.0

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
markdalgleishcommented, Sep 29, 2021

I believe this is caused by differing Babel targets between the client and server builds which means that the vanilla-extract Babel plugin can’t consistently create debug IDs for you.

As a workaround, you can apply an explicit debug ID yourself:

-export const [themeClass, vars] = createTheme({ ...tokens });
+export const [themeClass, vars] = createTheme({ ...tokens }, 'myDebugId');
2reactions
markdalgleishcommented, Sep 30, 2021

This is now fixed in @vanilla-extract/babel-plugin@1.1.1.

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 >
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 >
Fixing ClassName did not match error - DEV Community ‍ ‍
Warning : Prop `className` did not match. Server: Client: Enter fullscreen mode ... Tagged with nextjs, typescript, styledcomponent, react.
Read more >
Warning: Prop `className` did not match in Next.JS site with ...
By adding a unique identifier to every styled component, this plugin avoids checksum mismatches due to different class generation on the client and...
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