Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client generated different class names than server-side when using source-maps #688

Closed
mgroenhoff opened this issue May 29, 2018 · 0 comments
Labels

Comments

@mgroenhoff
Copy link
Contributor

I found that when I enable source maps, React is giving me a warning:

Warning: Prop className did not match. Server: "css-18slqts-Cell e148iowh2" Client: "css-ngphzi-Cell e148iowh2"

I looked into this and i found that when generating the class name, a hash is created from the generated CSS + some identifier name.

name = hashString(styles + identifierName) + identifierName

The styles in my case contains an inline source map URL and this URL is what is different (they're different because one is has a 'sourceRoot' property and contains Windows style paths, and the other does not have a 'sourceRoot' property and contains Unix style paths).

My suggestion is to only generate a hash of the styles up to the start of the source mapping URL comment (when process.env.NODE_ENV !== 'production' ofcourse).

I have tried a quick fix and replaced the previous line with the following and this seems to do the job for me:

    if (process.env.NODE_ENV !== 'production') {
      name = hashString(styles.slice(0, styles.indexOf("/*# sourceMappingURL=") || styles.length) + identifierName) + identifierName;
    } else {
      name = hashString(styles + identifierName) + identifierName;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants