Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
nickserv opened this issue Jul 4, 2018 · 7 comments
Closed

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

nickserv opened this issue Jul 4, 2018 · 7 comments

Comments

@nickserv
Copy link
Contributor

nickserv commented Jul 4, 2018

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.

@Timer
Copy link
Contributor

Timer commented 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!

@Timer Timer closed this as completed Jul 23, 2018
@nickserv
Copy link
Contributor Author

Do you have an example? I've never had issues with it, and I actually find it much harder to troubleshoot style changes without HMR because of the FOUC.

@bugzpodder
Copy link

I had a bad experience with it. I ended up in a state where there is a compile error or something and I could never resolve the issue even after if I fixed the code (stopping the devserver and restarting didn't help).

@Timer
Copy link
Contributor

Timer commented Jul 23, 2018

Style changes made in a .css file already hot reload, but reloading components is not safe.
Great examples that start to produce state errors are side-effect systems like redux-observable or redux-saga if you don't properly unsubscribe and re-subscribe to the reloaded module. Catching all edge cases and teaching people how to properly clean up after their components and registered events are hard.

@alexeyMohnatkin
Copy link

So maybe make this feature optional?

@murbanowicz
Copy link

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

@ozyman42
Copy link

Maybe there needs to be more of an effort to teach people how to properly clean up a module before it is swapped out for a new version. Maybe a better hot module API could aid in teaching people this.

@lock lock bot locked and limited conversation to collaborators Jan 9, 2019
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants