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

App reloads when saving a new class in a SCSS module #840

Open
MathiasBoisgardDev opened this issue May 16, 2024 · 1 comment
Open

App reloads when saving a new class in a SCSS module #840

MathiasBoisgardDev opened this issue May 16, 2024 · 1 comment

Comments

@MathiasBoisgardDev
Copy link

MathiasBoisgardDev commented May 16, 2024

Hello everyone,

I'll try to make a reproduction available when I have a bit of time if necessary, but first I wanted to make sure this was not a normal behaviour and/or if I'm missing something. (it concerns a corporation codebase which I can't really give access to)

So, first things first,
We're using the last version of react-refresh-webpack-plugin (0.5.13)
We recently started using the scss module approach and we did not have any problem prior to that


Issue: When we CREATE a new class in a styles.module.scss file, the application completely reloads. Whenever we just edit an existing class, the application fast reloads as expected.


I'm wondering if it is a normal behaviour or if something is off in our project configuration.

ps: I'm not even sure I'm asking the question in the right place, but I'm pretty sure it is :)

As you can see below, we have two different scss tests which differentiate "clasic" css/scss and another for the module.scss

webpack configuration

{
        test: /\.(css|scss)$/,
        exclude: aPath => {
          // The function excludes every .module.scss files and all node_modules css but d3- library
          if (aPath.includes('.module.scss')) {
            return true;
          } else if (aPath.includes('node_modules')) {
            // Transpile only modules containing 'd3-' in their name
            const hasD3 = aPath.includes('d3-');

            return !hasD3;
          }

          return false;
        },
        use: [
          {
            loader: 'style-loader', // creates style nodes from JS strings
          },
          {
            loader: 'css-loader', // translates CSS into CommonJS
            options: {
              importLoaders: 1,
            },
          },
          {
            loader: 'resolve-url-loader',
            options: {},
          },
          {
            loader: 'postcss-loader',
            options: {
              plugins: () => [autoprefixer()],
            },
          },
          {
            loader: 'sass-loader', // compiles Sass to CSS, using Node Sass by default
            options: {
              sourceMap: true,
              sourceMapContents: false,
            },
          },
          {
            loader: 'import-glob-loader',
          },
        ],
      },
      {
        test: /\.module.scss$/,
        use: [
          {
            loader: 'style-loader', // creates style nodes from JS strings
          },
          {
            loader: 'css-loader',
            options: {
              importLoaders: 1,
              modules: true,
            },
          },
          {
            loader: 'resolve-url-loader',
            options: {},
          },
          {
            loader: 'postcss-loader',
            options: {
              plugins: () => [autoprefixer()],
            },
          },
          {
            loader: 'sass-loader', // compiles Sass to CSS, using Node Sass by default
            options: {
              sourceMap: true,
              sourceMapContents: false,
            },
          },
          {
            loader: 'import-glob-loader',
          },
        ],
      },

small example :
syles.module.scss

.test {
  background-color: blue;
  padding-left: 12px;
}

If I just add a padding-right in .test, the application fast reloads and the new style is correctly applied

Whereas if I create a new class

.test {
  background-color: blue;
  padding-left: 12px;
  
  &__header {
    display: flex;
    ...
  }
}

The application will entirely reloads creating the new hash for test__header

@pmmmwh
Copy link
Owner

pmmmwh commented May 16, 2024

Hi, unfortunately I'm a bit occupied so I will try to take a look next week. I have a strong suspicion this is related to the use of CSS Modules (I'm not sure how creating a new class would change the output module in JS), but it could also be how style-loader interacts with HMR under the hood.

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

No branches or pull requests

2 participants