react-hot-loader: React module is not hot updated after my upgrade of webpack to v2 and webpack-dev-server to v2

If you are reporting a bug or having an issue setting up React Hot Loader, please fill in below. For feature requests, feel free to remove this template entirely.

Description

React module is not updated, after I edited ./src/components/DemoButton.js, changed something.

Expected behavior

Modules updated.

Actual behavior

image

Update traces are correct.

image

Breakpoints in render method was called. But nothing happened in DOM tree.

Environment

React Hot Loader version: 3.0.0-beta.6

Run these commands in the project folder and fill in their results:

  1. node -v: v6.6.0
  2. npm -v: 3.10.3

Then, specify:

  1. Operating system: macOS
  2. Browser and version: Chrome 55.0.2883.95 (64-bit)

Reproducible Demo

https://github.com/vivaxy/gt-react-scaffold/tree/db4a02582452772ac4533b3b0f199e831f339578

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 7
  • Comments: 23

Commits related to this issue

Most upvoted comments

@vivaxy @nikolaipaul this fixed my issue, have you tried it? https://github.com/gaearon/react-hot-loader/pull/240#issuecomment-258614348

i currently have:

renderApp(Root)

if (module.hot) {
    module.hot.accept(() => {
        renderApp(Root)
    })
}

rather than module.hot.accept('./containers/root', () => {

Thanks for that. I quickly went through, and it seems your code is probably not using ES2015 imports from webpack. Following code fixes the issue:

module.hot.accept('./components/App', () => {
  const NextApp = require('./components/App').default
  render(NextApp)
})

However, it should not be required when using webpack ES2015 built-in imports. To have that, in your .babelrc you should have either es2015 plugin or latest (latest currently includes es2015).

This is how to use latest with module: false (https://babeljs.io/docs/plugins/preset-latest/#usagees2015):

{
  "presets": [
    ["latest", {
      "es2015": {
        "modules": false
      }
    }]
  ]
}

I’ll mention it in the docs.

my hot reload works now. but only once. after that the state in all components below Root is lost. any idea why?

if (module.hot) {
    module.hot.accept(() => {
        const NewRoot = require('./containers/Root').default;
        ReactDOM.render(
            <AppContainer>
                <NewRoot store={store} history={history} />
            </AppContainer>,
            document.getElementById('root')
        );
    });
}

@bjudson - I spent like two days getting it to work before finding your comment, you’re a lifesaver.