HMR with webpack
See original GitHub issueDescription
HMR does not work.
Expected behavior
import React from 'react';
import ReactDOM from 'react-dom';
import App from './components/App';
import './index.css';
ReactDOM.render(
<App />,
document.getElementById('root')
);
if (module.hot) {
module.hot.accept('./components/App', () => {
ReactDOM.render(
<App />,
document.getElementById('root')
);
});
}
Hot updates should refresh page.
Actual behavior
Nothing happens.
see https://github.com/webpack/webpack-dev-server/issues/206
https://github.com/facebookincubator/create-react-app/blob/88c15d0988fcb456fc976cbe15823ed518470126/packages/react-scripts/scripts/start.js#L221 uses hot
option and https://github.com/facebookincubator/create-react-app/blob/88c15d0988fcb456fc976cbe15823ed518470126/packages/react-scripts/config/webpack.config.dev.js#L206 uses the plugin.
Removing either solved it for me.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Hot Module Replacement - webpack
Hot Module Replacement (HMR) exchanges, adds, or removes modules while an application is running, without a full reload. This can significantly speed up ......
Read more >Webpack's Hot Module Replacement Feature Explained
HMR allows you to exchange, add, or remove JavaScript modules while the application is running, all without having to reload the browser. This ......
Read more >What exactly is Hot Module Replacement in Webpack?
HMR is a way of exchanging modules in a running application (and adding/removing modules). You basically can update changed modules without a full...
Read more >Hot Module Replacement - SurviveJS
Webpack exposes the HMR interface through a global variable: module.hot . It provides updates through module.hot.accept(<path to watch>, <handler>) function and ...
Read more >Understanding webpack HMR beyond the docs - Jakob Lind
HMR (Hot Module Replacement) can give you a super smooth developer experience by automatically replace running code in the browser whenever you make...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I don’t think it “solved” the problem for you, it just refreshed the page.
Your example doesn’t work because it is written for Webpack 2. We still use Webpack 1. Here’s the version that works with Webpack 1:
Note that this resets internal state of components. Create React App doesn’t currently support preserving component state on hot reloading.
The examples you see are still the recommended way to do this.
However, no stable release depends on webpack 2. Please use the webpack 1 example for now. It should continue to work when we switch to 2.