Skip to content

Question: Enabling HRM Hot Module Replacement for React? #872

Closed
@edelgado

Description

@edelgado

Hi folks, the webpack-dev-server.md doc in this repo mentions that, in order to enable HMR for React we need add react-hot-loader as per these instructions.

Step one, enabling HMR was easy by adding the --hot option to the call for bin/webpack-dev-server in my Procfile. Additionally, I enabled the hmr setting in my webpacker.yml file.

Step 2 says to modify your root container to accept HMR:

 if (module.hot) {
   module.hot.accept('./containers/rootContainer.js', () => {
     const NextRootContainer = require('./containers/rootContainer.js').default;
     render(<NextRootContainer />, document.getElementById('react-root'));
   })
 }

Is that something that I need to handle outside of webpacker? I use react-rails and the react_component Rails view helper to integrate React components into Rails views.

I'm suspecting that HMR is not successful in my project because the React code is not setup to accept the hot modules. I get this every time:

image

Any help would be greatly appreciated!

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