react-hot-loader: Hot Reload doesn't work when starting inside a function
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
For the next branch, the hot reload does not work if the component being rendered is started inside a function.
Expected behavior
Being inside a function should not make any difference.
Actual behavior
It only works if the component being rendered is run at the top level. Meaning, the top level file that calls ReactDOM.render has to run directly, ReactDOM.render cannot be run inside a function that mounts the component which has been “hotted.”
Environment
React Hot Loader version: next, ^4.0.0-beta.12
Run these commands in the project folder and fill in their results:
node -v: v8.9.0npm -v: 5.5.1
Then, specify:
- Operating system: OS X 10.12.4
- Browser and version: Chrome 63
Reproducible Demo
Doesn’t work
https://gist.github.com/chrisabrams/e0fe9cf8ea7347fe2364cc46cf378412
Does work
https://gist.github.com/chrisabrams/293a08cfb98b6d8f0bb5aff4464f5874
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 18
Commits related to this issue
- Detect when hot for used for a render root. Fixes #765 — committed to theKashey/react-hot-loader by theKashey 6 years ago
- feat(react-hot-loader): detect wrong usage of `hot` (#766) Idea - detect the module execution start and the module execution end. During this event HotExportedComponent could be mounted and rendered... — committed to gaearon/react-hot-loader by theKashey 6 years ago
Any example of how to make it work with redux connect() ?
Only App.js and Index.js is hot-reloading rest doesnot.
@theKashey What JS error? First example works just fine for me. The issue I have is that I don’t know what the component is going to be, so I need to put it inside a function. I can’t export default it directly as it might be wrapped by another component. I was hoping that I could do something such as:
which would make it hot on the fly. That does not work though. To be more clear:
This works:
This does not work:
What specifically makes
hotbeing called inside a function cause[HMR] The following modules couldn't be hot updated: (Full reload needed)?