Include module.hot.accept in template or docs for HMR
See original GitHub issueI was pleasantly surprised to learn that CRA has built in HMR support, and enabling it can be as simple as adding module.hot && module.hot.accept()
to the end of src/index.js
. I no longer have a flash of content when trying to compare style differences between renders, which is very helpful in development. While I’m happy with my current implementation, I wish it was more discoverable without prior Webpack HMR experience, as the feature is disabled by default and not mentioned in the user guide or readme.
I propose adding module.hot && module.hot.accept()
to src/index.js
so it can be modified or removed by users with more complex setups. Alternatively if we can’t change the template, we can add an HMR section to the user guide to explain recommendations for a manual setup (assuming the user isn’t ejecting) and make the feature more obvious, or at least mention the feature is supported by react-scripts in the readme.
Note: It seems like #2304 is related but has a much wider scope. I’m interesting in a simple stopgap solution until we have that functionality built into react-scripts.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:8
- Comments:7 (3 by maintainers)
Top GitHub Comments
We are not going to advertise this as we suggest no one use HMR. It can lead to very difficult and hard to diagnose state bugs when used improperly.
Thanks for the suggestion!
If HMR is that bad, why React Native supports it natively?