Skip to content

Hot reload not updating the style for CSS Module in a React component #148

@kevinlaw91

Description

@kevinlaw91

When scss file is imported into a React component like this, hot reloading does not work as expected. The scss module was injected/replaced correctly, but new update was not applied.

import styles from "./Foo.scss";
class Foo extends React.Component {
 // ...
}

Let me clarify this. The old style is removed by style-loader, but the updated new style does not get injected back, causing component loses all of their styles no matter old or updated ones.

After some research I believe the problem is here:
https://github.com/webpack/style-loader/blob/master/index.js#L23

If I removed the if... statement, hot reloading will then work correctly, and doesn't seems like it will break anything.

		"	// When the styles change, update the <style> tags",
-		"	if(!content.locals) {",
		"		module.hot.accept(" + loaderUtils.stringifyRequest(this, "!!" + remainingRequest) + ", function() {",
...
-		"	}",

I can create a PR for this. But I want don't want remove the if... statement just like that. @sokra May I know what is the purpose of this check? Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions