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

A Bug in Reloading JS Bundle since react-native@0.29 #9617

Closed
richarddlu opened this issue Aug 28, 2016 · 7 comments
Closed

A Bug in Reloading JS Bundle since react-native@0.29 #9617

richarddlu opened this issue Aug 28, 2016 · 7 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@richarddlu
Copy link

A very nice improvement of React Native since version 0.29 is using
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
to switch using packager server with DEBUG mode or pre-bundle with RELEASE mode in an actual device.

However it does not work when the packager server is already running when building the IOS product.

I guess the reason is caused by that the program decides to still use the pre-bundle when it fails to start a packager server since the 8081 port is already taken by another running packager server.

A workaround is to stopping the running packager server before building. But the bug still needs to be fixed since it causes a lot confusion.

@richarddlu richarddlu changed the title A Bug in AppDelegate.m File A Bug in Reloading JS Bundle since react-native@0.29 Aug 28, 2016
@afilp
Copy link

afilp commented Sep 6, 2016

I use v0.32 (macOSX on an actual iPad) and I only have these 4 options on the Developer Menu (when shaking the iPad):

Reload
Debug JS Remotely
Show Inspector
Show Perf Monitor

Why can't I see the "Hot reload" and "Live Reload" options?

@guilhermebruzzi
Copy link
Contributor

The same issue happened to me with RN 0.33 (and 0.32) and only on iOS device. On android and ios simulator it works.

The reload action doesn't work on an iOS device. It doesn't even make the request to the packager, it only gets the pre-bundle like @richarddlu explained. I even tried to kill the packager before running like @richarddlu suggested, but the problem persisted.

And the "Hot reload" and "Live Reload" options disappeared like @af7 said.

A similar issue was closed but without a solution for this case: #8461

I finally found the problem in my case and a workaround:

The script that runs on "Bundle React native code and images" build phase is:
./node_modules/react-native/packager/react-native-xcode.sh

It gets the ip of the machine with (en0 is ethernet):

IP=$(ipconfig getifaddr en0)

But i'm using wifi in mac and in my case like is explained in: http://apple.stackexchange.com/questions/20547/how-do-i-find-my-ip-address-from-the-command-line

Only this command returns the IP address (en1 is wireless):

IP=$(ipconfig getifaddr en1)

So i created a separate file react-native-fix-ip-xcode.sh with the following code:

set -x
DEST=$CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH

if [[ "$CONFIGURATION" = "Debug" && "$PLATFORM_NAME" != "iphonesimulator" ]]; then
  PLISTBUDDY='/usr/libexec/PlistBuddy'
  PLIST=$TARGET_BUILD_DIR/$INFOPLIST_PATH
  IP=$(ipconfig getifaddr en0)
  if [ -z "$IP" ]; then
    IP=$(ipconfig getifaddr en1)
  fi
  $PLISTBUDDY -c "Add NSAppTransportSecurity:NSExceptionDomains:localhost:NSTemporaryExceptionAllowsInsecureHTTPLoads bool true" "$PLIST"
  $PLISTBUDDY -c "Add NSAppTransportSecurity:NSExceptionDomains:$IP.xip.io:NSTemporaryExceptionAllowsInsecureHTTPLoads bool true" "$PLIST"
  echo "$IP.xip.io" > "$DEST/ip.txt"
fi

And added ../react-native-fix-ip-xcode.sh after ../node_modules/react-native/packager/react-native-xcode.sh on the same Build Phase.

And it worked! :)

@satya164 Do you think the above code in "react-native-fix-ip-xcode.sh" is a valid pull request to "react-native-xcode.sh". So it also find the IP on en1 (wireless)?

@satya164
Copy link
Contributor

I'll let someone with more experience with Code answer that.

cc @Kureev

@Kureev
Copy link
Contributor

Kureev commented Sep 16, 2016

Hey everybody!

First of all, let's try to summarize a bunch of problems you experience:

  • Pre-bundling doesn't work if there is an existing instance of packager running
  • Pre-bundled version doesn't have a hot module replacement / live reload options
  • IP detection is incorrect (sometimes)

Now, let's try to address these issues:

  • Pre-bundling doesn't work if there is an existing instance of packager running. I can understand why it happens, but what would be a desired behavior then? Should we kill an existing packager instance or should we spawn an another one on a different port?
  • Pre-bundled version doesn't have a hot module replacement / live reload options. It does make sense to me. If your packager doesn't server your JS files (that happens now when you deploy your application to device "by default". See Fix to make bundling available for iPhone simulators again #6352 discussion about packager/react-native-xcode.sh and 8c29a52 that actually changes this behavior).
  • IP detection is incorrect (sometimes). I'll take a look into packager and IP detection code to find a way how we can make it work for you (i.e. expose an option to hook your ethN from the ENV for instance)

Please, let me know if this feedback makes any sense to you or you know the way to improve it ❤️

guilhermebruzzi added a commit to guilhermebruzzi/react-native that referenced this issue Sep 17, 2016
… device

Find your mac's IP Address in en1 (wireless) if it doesn't find it in en0 (wired/ethernet) when react native xcode's script runs on iOS device
@guilhermebruzzi
Copy link
Contributor

Thanks @Kureev your feedback definitely helped! :D

This issue didn't happen to me: Pre-bundling doesn't work if there is an existing instance of packager running. It never worked even when i killed the existing instance of packager.
Maybe by fixing the IP address detection this issue won't occur anymore with @richarddlu, as it worked for me.

I agree with you that if it uses a pre-bundled version, it shouldn't have a hot module replacement / live reload options.

In case of the IP detection i believe this PR will fix the issue: #9964

Because the IP address should be in either en0 or en1 depending on how you access the internet.
I don't know if a option to hook the ethN on ENV makes sense, maybe a option to pass your IP address via ENV could be even better, if the script doesn't already find it.

guilhermebruzzi added a commit to guilhermebruzzi/react-native that referenced this issue Sep 18, 2016
… device

Find your mac's IP Address in en1 (wireless) if it doesn't find it in en0 (wired/ethernet) when react native xcode's script runs on iOS device
guilhermebruzzi added a commit to guilhermebruzzi/react-native that referenced this issue Sep 19, 2016
… device

Find your mac's IP Address in en1 (wireless) if it doesn't find it in en0 (wired/ethernet) when react native xcode's script runs on iOS device
guilhermebruzzi added a commit to guilhermebruzzi/react-native that referenced this issue Sep 19, 2016
… device

Find your mac's IP Address in en1 (wireless) if it doesn't find it in en0 (wired/ethernet) when react native xcode's script runs on iOS device
guilhermebruzzi added a commit to guilhermebruzzi/react-native that referenced this issue Sep 21, 2016
… device

Find your mac's IP Address in en1 (wireless) if it doesn't find it in en0 (wired/ethernet) when react native xcode's script runs on iOS device
@guilhermebruzzi
Copy link
Contributor

guilhermebruzzi commented Sep 23, 2016

@Kureev @vjeux Hi Guys, can you take a look at this issue and the PR I mentioned (#9964) to see if it makes sense to be part of RN 0.34? I can update with the base branch if it looks ok for you and that would be great for our RN team, TY! :D

guilhermebruzzi added a commit to guilhermebruzzi/react-native that referenced this issue Sep 23, 2016
… device

Find your mac's IP Address in en1 (wireless) if it doesn't find it in en0 (wired/ethernet) when react native xcode's script runs on iOS device
@ghost ghost closed this as completed in 8adf78f Sep 26, 2016
@elxris
Copy link

elxris commented Oct 9, 2016

When this will be pushed to a stable release?
Is not in v0.35.0-rc.0
https://github.com/facebook/react-native/blob/v0.35.0-rc.0/packager/react-native-xcode.sh#L77

cpojer pushed a commit to facebook/metro that referenced this issue Jan 26, 2017
Summary:
React native's reload javascript option doesn't always work on iOS devices since version 0.29, as described in facebook/react-native#9617

It only doesn't work when you have a mac on a wireless connection, because react-native-xcode.sh can't find your IP address correctly in this case and will just fallback to use the pre-bundling option on your app.

This small change in react-native-xcode.sh fixed this issue for our project and should fix this issue for all mac users that use wireless connection and that will run a debug version of the app on a real iOS device.
Closes facebook/react-native#9964

Differential Revision: D3923035

fbshipit-source-id: 436cfa2103e10221270034233552ce34720505d3
@facebook facebook locked as resolved and limited conversation to collaborators May 24, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 19, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

7 participants