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

Server generated css class name is different from the one generated on the client #265

Open
rahulrsingh09 opened this issue Jul 15, 2019 · 2 comments

Comments

@rahulrsingh09
Copy link

@rahulrsingh09 rahulrsingh09 commented Jul 15, 2019

I am trying to get Css Modules working in React SSR.

This is my webpack config

module: {
        rules: [
            {
                test: /\.jsx?$/,
                exclude: /(node_modules|bower_components)/,
                loader: "babel-loader",
            },{
                test:/\.(s*)css$/,
                use: [
                    {
                        loader: MiniCssExtractPlugin.loader,
                    },

                    {
                        loader: 'css-loader',
                        options: {
                            modules: {
                                mode: 'local',
                                localIdentName: "[name]__[local]___[hash:base64:5]"
                            },
                            import: true,
                            importLoaders: true,
                        }
                    },
                    {
                        loader: "sass-loader",
                    }
                ],
            },
        ]

And my babelrc file

"env": {
   "test": {
     "presets": [
       "react"
     ],
     "plugins": [
       ["react-css-modules", {
         "generateScopedName": "[name]__[local]___[hash:base64:5]"
       }],
       "transform-es2015-modules-commonjs",
       "@babel/plugin-transform-runtime"

     ]
   }
 }
}

I have made the local ident name same in both cases but still the name on the client is different than on the server for the element.

generated on server styles.css

.Home__Container___KBMxU {
  display: flex;
  width: 600px;
  height: 300px;
  border: 2px solid red; }

And on on the client is Home__Container___2eVzQ

What is causing this Name mismatch in styles ?

@rahulrsingh09 rahulrsingh09 changed the title The Server generated css name is different from the one generated on the client Server generated css class name is different from the one generated on the client Jul 15, 2019
@shabailiu
Copy link

@shabailiu shabailiu commented Aug 6, 2019

I had the same issue.

What fixed it for me was making sure the context for the plugin matches that in your webpack context.

@SHERlocked93
Copy link

@SHERlocked93 SHERlocked93 commented Oct 28, 2020

did you fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants