Skip to content

[styles] Strict Mode support #18018

@bmvantunes

Description

@bmvantunes

First of all, thank you all very much for the amazing material-ui.

I started my project from https://github.com/mui-org/material-ui/tree/master/examples/nextjs

Lately, I started to notice that my page after hydration looked weird - some styles were missing and some other times they were not applied to the expected elements.

Using React.StrictMode it tells me the following error:
Warning: Prop className did not match. Server: "MuiSvgIcon-root makeStyles-lightBulb-47" Client: "MuiSvgIcon-root makeStyles-lightBulb-48"

Current Behavior 😯

Looks like the classNames generated at server rendering are different to the ones generated at browser rendering time.

Expected Behavior 🤔

Server-side rendering and client-side rendering should generate the same class names.

Steps to Reproduce 🕹

Steps (Code Sandbox):

  1. https://codesandbox.io/s/nextjs-hge3h:
  2. Open developer tools (F12) and refresh code sandbox:
  3. You'll see:
    Warning: Prop className did not match. Server: "MuiSvgIcon-root makeStyles-lightBulb-47" Client: "MuiSvgIcon-root makeStyles-lightBulb-48"

Steps (Running locally)

  1. git clone https://github.com/bmvantunes/material-ui.git
  2. cd material-ui/examples/nextjs
  3. npm install
  4. npm run dev
  5. Open the browser, F12 and you'll see the error:
    Warning: Prop className did not match. Server: "MuiSvgIcon-root makeStyles-lightBulb-47" Client: "MuiSvgIcon-root makeStyles-lightBulb-48"

Context 🔦

The reproduction of the error will look something like:
next-material

The only difference between my repository (example) and material-ui/examples/nextjs is the React.StrictMode instead of React.Fragment inside _app.js

Your Environment 🌎

Tech Version
Material-UI latest (4.51)
React latest (16.11.0)
Browser Any browser
Node 12
Nextjs latest (9.1.1)

PS - I saw that in the past some issues were created for something similar to this, but I couldn't apply the solutions on those issues to this specific issue. Most of those issues were using styled-components and none was using the material-ui example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: importantThis change can make a difference.scope: stylesSpecific to @mui/styles. Legacy package, @material-ui/styled-engine is taking over in v5.type: bugIt doesn't behave as expected.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions