1 year ago

#296451

test-img

Nathan Stowell

React Native app doesn't connect to Metro bundler on first launch

I am working in an established iOS app. I have backfilled the app to use React Native, and so far that part is working fine. The problems I am running into are:

  1. The Xcode build takes a very long time, and any JavaScript errors will cause the initial build to fail
  2. Once the build succeeds and the app is started (on a physical device), the initial launch says it is trying to connect to Metro, but it never actually does. Instead the RN view pops into place without downloading from the server. At this point I cannot refresh the JavaScript from the Metro bundler, it states that there is no app connected. Additionally, if I shake the device and try to select "Debug in Chrome" the screen will go blank and no longer respond.
  3. If I do not try to open the developer menu and select "Debug in Chrome", but instead just force close the app, when I re-launch the app (not rebuild from Xcode) it will connect to Metro and download the JavaScript bundle like normal. At this point I can select "Debug in Chrome" and it will connect and work just fine.

All-in-all, this isn't a huge issue as there is a workaround available to me. However, it doesn't feel right and I would like to figure out what is going on.

My theory is that during the build process, Xcode is bundling the React Native code as if it is trying to do a production build (I have verified the scheme is set to debug) in a debug executable. I have tried detecting __DEV__ and it is true, so I cannot figure out how to get the app to connect to Metro directly after the Xcode build.

Thank you all in advance for any help you can offer.

javascript

ios

xcode

react-native

metro-bundler

0 Answers

Your Answer

Accepted video resources