HMR works as expected but doesn't force render the updated component. I can see in the console:
[WDS] App hot update...
[HMR] Checking for updates on the server...
[React Transform HMR] Patching Root
[HMR] Updated modules:
[HMR] - ./src/app/Root/RootContainer.js
[HMR] App is up to date.
And nothing changes in the UI until I click on something that triggers the render of Root - after that I do see that the component was updated.
This started after updating React from 15.6 to 16.2.
Root should be re-rendered (forceUpdate?) once it's patched.
It doesn't re-render. It just updates.
React Hot Loader version: 3.1.3
node -v: v8.9.1npm -v: 5.4.2
Operating system: Windows 10 X64
Not sure I can get such a thing done. Is there any reason you can think of the file will be patched as it should but wouldn't re-render?
What does React Transform HMR doing here?
Did you wrap all the things with AppContainer?
Did you wrap all the things with AppContainer?
I have the AppContainer around my root component.
What does
React Transform HMRdoing here?
Don't know. I have babel-plugin-react-transform in my devDependencies.
This is my .babelrc file:
{
"env": {
"development": {
"presets": ["react-hmre"],
"plugins": [
"transform-react-display-name",
"transform-decorators-legacy",
"react-hot-loader/babel"
],
"compact": false
},
"test": {
"plugins": ["transform-decorators-legacy"],
"compact": false
},
"production": {
"plugins": [
"transform-decorators-legacy",
"transform-react-remove-prop-types",
"transform-react-constant-elements",
"transform-flow-strip-types",
"transform-react-inline-elements"
],
"compact": true
}
},
"presets": ["es2015", "react", "stage-2"]
}
This is my render function:
import { AppContainer } from 'react-hot-loader'
import Root from './app/Root/RootContainer';
...
ReactDOM.render(
<AppContainer>
<Root history={() => history} store={() => store} routes={() => routes} />
</AppContainer>,
document.getElementById('app')
);
Looking good, but please use env preset, not react-hmre
HMRE was designed to work with ReactHotLoader V1, not V3.
@theKashey Thanks.
Any idea how I can understand why it doesn't re-render?
I tried debugging the patching of the file but didn't see where it calls for a render.
@adamtal3 - look like you did not enable harmony modules. Do you re-require App on module hot update?
See https://github.com/gaearon/react-hot-loader/pull/700
I don't re-require the App on module hot update. Should I? Everything somehow worked perfectly with react 15.6..
I tried adding "{ "modules": false }" to the env preset in my babel file but it fails with Missing class properties transform.
Isn't "presets": [ ["env", { "modules": false }] ] what you meant? Am I missing something?
In case you dont specify not to transpile modules you have to call Root = require('./app/Root/RootContainer') manually on module.hot.accept, before you render the new code.
Without re-require you will render the old code, and next webpack will update code, as long nobody actually "accepts" it.
Seems that simply adding a module.hot.accept(); solved the issue for me.
@theKashey - Thanks a lot for the help. Tell me if I should of done anything differently (if it works now, should I require the root container anyway?).
Yep, without modules:false you should.
Most helpful comment
Seems that simply adding a
module.hot.accept();solved the issue for me.@theKashey - Thanks a lot for the help. Tell me if I should of done anything differently (if it works now, should I require the root container anyway?).