react-native: Hot Reloading is not working
- [ x ] I have reviewed the documentation
- [ x ] I have searched existing issues
- [ x ] I am using the latest React Native version
Hot Reloading is not updating the view in Android device even we have made changes. It happens after a Reload triggered from the device.
I have tested this issue in v0.55.2, 0.54.0 and 0.53.3. The only version that has hot reload still functioning well is 0.53.3, this problem starts occuring from 0.54.0
Environment
OS: Windows 10 Node: 6.11.5 Yarn: 1.3.2 npm: 4.6.1 Watchman: Not Found Xcode: N/A Android Studio: Version 3.0.0.0 AI-171.4443003
Packages: (wanted => installed) react: 16.3.1 => 16.3.1 react-native: 0.55.2 => 0.55.2
Steps to Reproduce
- Run
react-native init NoHotLoad
- Run
react-native run-android
- When the project loaded, enable the Hot Reloading
- Make changes to the App.js, like editing the text. The change should appear in the device.
- Do Reload on the device
- Repeat step 4, but the change won’t appear at the device. Just a toast of Hot reloading appears.
Another scenario: after installing the app to the device, replace step 2 above with npm start
should also reproduces this problem.
Expected Behavior
The Hot Reloading should be able to hot-reload all the changes, regardless number of attempts of reload.
Actual Behavior
The Hot Reloading only works before a Reload action triggerred
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 98
- Comments: 123 (3 by maintainers)
Commits related to this issue
- add temporary fix for the hot reload: https://github.com/facebook/react-native/issues/18899. — committed to rawtxapp/rawtxapp by rawtxapp 6 years ago
- Changed targetSdk and buildToolsVersion in android/build.gradle to 28. Bundled images and resources as they would otherwise not be included in build. edited gradle.properties to supress a warning abou... — committed to careerfairsystems/arkad-app by Alexander-Mjoberg 5 years ago
@moshanghan the link is up. Don’t know if it’s related to your ISP. Anyway here it is: Filename:
react-native/local-cli/server/util/attachWebsocketServer.js
We managed to get it working on react-native@0.57.8 and react@16.6.3 by pinning react-deep-force-update to 1.1.2
The new implementation has landed in master! We’re calling it Fast Refresh.
You can see a demo of Fast Refresh here: https://mobile.twitter.com/reactnative/status/1144629612921720833
Note: We expect it to be available in 0.61. (Not 0.60.)
I’ll leave this issue open until I verify that it indeed solves the reproduction cases posted in this thread.
@EduVencovsky Sorry, this isn’t helpful without a reproducing project.
@chuttam Thanks for a repro case. I will check whether my changes fix it. (I expect them to).
If anyone has more reproducing cases, now is the time to post them.
I have 3 different projects with versions 0.51, 0.54 and 0.55. The first project works fine. I think this happened after a they announced new metro (v0.52 I guess)
You can see detailed bug and debug report the link above. I don’t know when there will be a fix, meanwhile, you can use the simple dirty hack I did for my project:
https://gist.github.com/cihadturhan/dda54a25eae398d7db0b06292f0cac9c
I’ll reopen since I’m working on a new implementation. However I don’t know if the problems I’m fixing are related to the problems in this thread. Some of them might be, some of them probably aren’t.
I’ll close this after I land the new implementation. If you have a problem after the release that contains it, it would be best to create a new issue with a concrete reproducible example and/or video.
For now let’s keep it open.
If you have any concrete cases that are still broken please post reproducing examples with instructions in this thread. This is your chance to see them fixed.
i can confirm, if the root component is a class, it’s working fine for me
same here on react-native@0.57.4, the experience really sucks.
0.57.7 still faces this issue… Any workaround for this patch? Thanks.
Check out below link to enable hot reloading in react native application : Enable Hot Reloading In React Native https://www.skptricks.com/2018/07/enable-hot-reloading-in-react-native.html
On Sun, Jul 29, 2018 at 6:04 AM Michael Lustig notifications@github.com wrote:
deleting
.git/index.lock
might helpFor me patching it in node_modules/metro/src/lib/attachWebsocketServer.js.flow worked. 👍
@cdreier 0.60 is not going to contain any of these fixes, sorry. You’re still testing the old implementation. Fast Refresh is slated for 0.61. There isn’t an easy way for you to test it yet, unfortunately, but I can try your test case later. Thanks for making it!
In android, when I press
Ctrl + S
it shows the android toast withHot Loading...
But it doesn’t change anything. Only when I manually reload it (and the green bar on the top appears), it changes.When I enable live reloading, one weird thing happens. In the metro bundler, after the first loading, it always shows
100.0% (1/1), done.
like if there are no changes.I’m using react-native 0.59.3
Is there any word on when this might be fixed? It slows down the development process quite a bit and the issue has existed now for longer than a month. We just updated to the last RN version a few days ago and now we are considering to downgrade again.
@cihadturhan’s fix works like a charm.
So if you wish to stay on RN 54+, you can perform an unfortunate but helpful hack until this fix drops:
vendor/attachWebsocketServer.js
(or similar)package.json
postinstall
script:Refer to this article : https://www.skptricks.com/2018/07/enable-hot-reloading-in-react-native.html
I’m not sure if this is a know issue or if this is related but I had to change root component to be class component instead of function component.
This is a show-stopper bug for RN 54+. Hard to believe there can be people using RN 54 and RN 55 without any hot-reload.
@gaearon - Here is a tiny project (essentially the result of
react-native init
) that replicates the issue.https://github.com/chuttam/react-native-hotreload-issue18899
The project’s README has specific instructions for replicating the Hot Reloading malfunction. As @jsslai and @cdreier confirmed, changing the root component from a class to a function component triggers the issue.
Neither the single solutions or a combination of @gideaoms and @sbycrosz answers work for me (react-native@0.58.6). I also tried all the other suggestions from above. (rm node_modules, remote debugging, etc) Now the screen stays black after I fixed an error that caused a red screen. Only reload helps.
react-native start --reset-cache --max-workers=1
For quick fix (Actually its a bad practice)
How to fix hot reloading: 1.) DO NOT attempt to upgrade to 0.57.04 – It will fail! 2.) Start a brand new react-native 0.57.04 project.
same as React native 0.57.2 I have to use live reload to reload entire project, it’s annoying
@lustigdev your issue is different. Arrow functions doesn’t work with hmr by default. You can use the following plugin: https://github.com/bvic23/babel-plugin-functional-hmr
Confirming that @sbycrosz 's fix is working on 0.58.5 with iOS simulator!
It is super crucial and to me it’s a killing feature compared to other frameworks/libraries. It speeds up development a lot.
I’m on RN 0.55 and can’t make it work. @cihadturhan fix is not working here. Any one got another workaround?
Just checked that this is fixed.
(But you probably should avoid creating component inheritance hierarchies.)
watchman watch-del <path-to-project-directory> watchman watch-project <path-to-project-directory>
And rebuilding the project fixed for me.
@jan-happy I’m sorry, but I did not investigate the reason in depth. In fact, I found out after researching a lot. I realized that Hot Reloading was working with other editors, but it did not work with VSCode. After some tests, I discovered that opening another project without closing the VSCode or reloading the VSCode after installing an extension was breaking the Hot Reloading.
one of the hot reload issues is related to visual studio code, if you are working on a project and for some reason, you click reload visual studio code, then hot reload will stop working. My tip is: reopen visual studio code every time you install a new extension or when you want to open another project.
Same on newest one for me too - looks like it hangs ONLY after you type in invalid code - anything valid will be reloaded but once node pickup the invalid code it will not hot-reload it anymore.
if non of above solution works, check your component life cycle method.
I got the problem because i use async on it
componentDidMount = async () => {...}
when i change back without async, hot reloading works fine
I can confirm that this fixed the problem for me when upgrading my project’s React Native version from
0.56.0
to0.57.8
.My
yarn.lock
hadreact-deep-force-update
locked to version1.1.1
.I manually removed the
react-deep-force-update
from myyarn.lock
and ranyarn install
after that to update the lock file to use version1.1.2
. Then when I restarted the packager usingyarn start --reset-cache
hot loading started working again.I noticed the same problem, I’m using 0.57.7 on iOS simulator. I think it used to work in 0.57.2. For me the “Hot Loading…” notification appears but the view is not re-rendered until I perform a reload (Cmd-R).
(Xcode is actually 10.1, I just have two copies installed)
Just spotted this fix here merged to master: https://github.com/facebook/react-native/pull/22412
😄
How can this get screwed up? It’s promised out-of-the-box, as we all expect it to be, and work. 🤦♂️ Finally upgraded from 0.50.3, to 0.57.5, and now the development experience suck, after having hot-reload for over 1 year working on RN every day.
Hot reloading only seems to work for me with remote debugging on.
Hi, for anyone using Typescript, try changing your
tsconfig.json
like this:See this article
In this case I have to abandon importing from a
json
file.I’m using RN 0.55.3.
Got it fixed using
Into
package.json
then runningyarn
. You can remove it afterwards. Thanks @sbycrosz !Recently my project got performance improvement by changing from React.Component to React.PureComponent so the i got an HMR toast in android but the change didn’t reflect in the UI. Solved by following this in SO: https://stackoverflow.com/questions/46013170/react-native-0-47-1-hot-reload-is-not-reflecting-code-changes-on-macos
For me using XCode 10 and 0.57.7: Hot reload enabled if I make change - I can see Hot reloading bar on top and after a while app is just closed (probably crashes). For me hot reload works if debug is running at the same time.
Upgrading from 0.48 to 0.57. Hot reloading not working. Tried above steps, nothing is work. Deleted package-lock.json.
npm install
, regenerate package-lock.json. Hot reloading working.@fogil I created a brand new react-native 0.57.4 project and it still doesn’t work
Switch back to old one : react-native init <projectname> --version react-native@0.55.4 .
On Tue, Oct 30, 2018 at 9:57 PM jamessawyer notifications@github.com wrote:
It’s not work for RN 0.57, because file attachWebsocketServer.js is not exist.
Maybe, some have solution for this problem?
Thanks dude!! your solution fixed my issue. I was experiencing a 20+ seconds delay in seeing the HotLoading on my phone, now i see it almost instantly as soon as i save.
I’m running into this on
0.56
, though the file that @cihadturhan refers to seems to have been moved to themetro
package; not sure how this patch ought to be used there.Is this the issue tracking the underlying Metro problem? https://github.com/facebook/metro/issues/165
Hope this gets resolved legitimately sometime rather than requiring patching it like this.
It is very simple. Just sharing link, it will help you to enable hot reloading in react natve.
Link : https://www.skptricks.com/2018/07/enable-hot-reloading-in-react-native.html
On Thu, Jul 19, 2018 at 10:24 PM Lucas Michailian notifications@github.com wrote: