-
-
Notifications
You must be signed in to change notification settings - Fork 470
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
Aborting CSS HMR due to changed css-modules locals when using react-hot-loader #320
Comments
@pattiereaves very strange, can you create minimum reproducible test repo? |
I've faced the same issue while using |
Also just stumbled upon this problem, downgrading to 0.19 seems to fixed it. |
@lydell this seems related to #298 and there's a repro case linked here. It also works for me when adding a local on 0.19.1, and your change was published in 0.20. I'm using babel-preset-react-hmre. |
I'm also getting the same error. "style-loader": "^0.20.3",
|
Same error |
We have also started to see this since upgrading to webpack 4 and related loaders etc. |
same error
This occurs when create selector, and add properties to empty selector. // create
.text-input {
margin-top: 0.4em;
}
// Error: Aborting CSS HMR due to changed css-modules locals. .text-input {
}
// add new properties
.text-input {
margin-top: 0.4em;
}
// Error: Aborting CSS HMR due to changed css-modules locals. HMR still works when adding new properties to selector which have one or more properties. .text-input {
margin-top: 0.4em;
}
// add new properties
.text-input {
margin-top: 0.4em;
margin-bottom: 0.4em;
}
// hmr works. |
I'm also seeing the behavior that @zeakd detailed where HMR with CSS modules works fine part of the time (specifically, as long as the changes do not result in a selector being added or a selector without any declarations having one or more added). This is despite not actually using any variables at all, which makes the message rather confusing. Running style-loader v0.21.0. |
Fix this please. |
Just to give some context: Before #298, without react-hot-loaderChanging anything in a CSS file caused a full page reload! Super sad! After #298, without react-hot-loaderChanging properties in CSS hot reloads! Yay! But if classes are added, removed or changed the whole page is reloaded. Why? Because your React render methods need to run again with the new classes. Before #298, with react-hot-loaderI guess CSS changes were always hot reloaded? After #298, with react-hot-loaderHot reloading fails (requiring manual page reload?) if classes are added, removed or changed? Have I understood that correctly? Why does this happen? Because of #298 (comment):
My guessreact-hot-loader needs to catch the thrown error and ignore it, because since the React code is hot loaded the render methods always re again with the new classes so the case doesn't apply. So it might be that something needs to be done in the react-hot-loader repo, not this one! Or, if that doesn't work out, maybe we need an option? |
I took a closer look at @tpolovyi's demo (from #320 (comment)) (https://github.com/tpolovyi/style-loader-demo) and it does not involve react-hot-loader at all! The difference compared to my demo used to test the PR (https://github.com/lydell/css-hmr-bug/tree/fix) is that I use webpack-dev-server while @tpolovyi uses webpack-dev-middleware directly in express. And in his example, the I think we need help from somebody who deeply understands how HMR works in webpack. |
…s-modules locals,而官方一直未解决:webpack-contrib/style-loader#320
@lydell, can you please explain again why do we need to do full reload when we added a new rule? /* Button.css */
.Foo {
color: red;
} import React from 'react'
import styles from './Button.css'
export default class Button extends React.Component {
render() {
return <div className={styles.Foo}>{this.props.children}</div>
}
} Before your PR, I could add a new class |
Somebody can create minimum reproducible test repo and describe in readme what actually happens and what expected (and what was in old version)? |
@beshanoe thanks, after holidays we will refactor |
@beshanoe If you first add |
@lydell yeah I understand there are bunch of edge cases and I can't say for sure which solution gonna cover them all, but when using react-hot-loader with CSS modules and webpack-hot-middleware, it worked before and now it doesn't, at least because apparently webpack-hot-middleware doesn't support reloading on throwed error. |
@lydell actually I was completely ignoring the fact that HMR was turned off for css modules before, so for those who uses them only in react app with RHL, current fix is to provide {
test: /\.css$/,
use: [
{
loader: "style-loader",
options: {
hmr: false
}
},
{
loader: "css-loader",
options: {
modules: true
}
}
]
} and make |
tried @beshanoe solution and disabled hmr in "style-loader"; it works, however, it causes react rerender every time scss content changed. downgrade package to 0.19.1 worked for me. |
@cyrus-d can you create minimum reproducible test repo? |
@evilebottnawi this is the boilerplate that I have modified to reproduce the problem, please look into the webpack/modules.js for configurations: https://github.com/Cyrus-d/webpack-react-boilerplate This is what happens: hope it helps. |
Hey @cyrus-d |
@beshanoe thanks for pointing that out, actually at first, I did had hmr option under style-loader, but it caused react rerender the app, look into it closely I have noticed that the react hot loader was configured incorrectly. so yes, setting hmr to false indeed solved the problem. Thanks for the help. |
Hey, where are we at with this issue? I've downgraded for the time being, but I sure would like to get back on the update track and still have hmr. |
@martinkadlec0 PR welcome |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
When using the latest version of style-loader and react-hot-loader, the page will reload every time a change is made to a css file (regardless of the change being to a property or a selector). It provides the following error when doing a full page reload:
Aborting CSS HMR due to changed css-modules locals.
I believe this PR introduced the issue.If the current behavior is a bug, please provide the steps to reproduce.
I am not entirely sure what about my configuration is causing this issue, but I suspect it is the combination of using css modules, react hot loader and style loader. See this comment. Downgrading to style-loader@0.19 fixes the issue. (Changes to CSS are applied to the page without a complete reload)
What is the expected behavior?
I can make changes to css and the changes will be applied using HMR.
If this is a feature request, what is motivation or use case for changing the behavior?
n/a
Please mention other relevant information such as your webpack version, Node.js version and Operating System.
node 8, npm 5
stylel-loader@0.21.0
"css-loader": "^0.28.11",
"react-hot-loader": "^4.0.1",
"webpack": "^4.2.0",
"webpack-dev-server": "^3.1.1"
The text was updated successfully, but these errors were encountered: