question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Include module.hot.accept in template or docs for HMR

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
Timercommented, Jul 23, 2018

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!

1reaction
murbanowiczcommented, Nov 6, 2018

If HMR is that bad, why React Native supports it natively?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hot Module Replacement - webpack
Accept updates for the given dependencies and fire a callback to react to those updates, in addition, you can attach an optional error...
Read more >
HMR API - Vite
A module that "accepts" hot updates is considered an HMR boundary. Note that Vite's HMR does not actually swap the originally imported module:...
Read more >
How to detect/enable HMR for objects passed into functions ...
The module which import s the changed module need to accept it. Example: (Note: babel rewrites import so you need to use require...
Read more >
hot-module-replacement | Meteor API Docs
Hot Module Replacement (HMR) is a method of updating javascript modules within a running application. This reduces the feedback cycle while developing, ...
Read more >
Hot Module Replacement - KVision Guide - GitBook
The template project contains files necessary to utilize the HMR (Hot Module ... import pl.treksoft.kvision.hmr.module. import kotlin.browser.document.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found