-
Notifications
You must be signed in to change notification settings - Fork 24.8k
iOS DX: Automagically find packager's IP address #6345
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
Conversation
By analyzing the blame information on this pull request, we identified @tadeuzagallo, @foghina and @geof90 to be potential reviewers. |
if ([bundleURL.scheme hasPrefix:@"http"]) { | ||
host = bundleURL.host; | ||
port = [bundleURL.port integerValue]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicklockwood I think we've talked about reusing bundleURL
in RCTWebSocketExecutor
to reduce amount of URL configurations needed, because in most cases the debugger is running on the same machine as the packager. What do you think about the proposed solution?
Side note: this will fail to guess the debugger URL when loading from file, but we already have tons of problems with debugging offline files: Chrome doesn't support loading from file:///
protocol (without additional flags), we don't store sourcemaps by default, there is no ability to load file from remote device, etc.
@frantic updated the pull request. |
1 similar comment
@frantic updated the pull request. |
DEST=$CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH | ||
|
||
if [[ "$CONFIGURATION" = "Debug" && "$PLATFORM_NAME" != "iphonesimulator" ]]; then | ||
ipconfig getifaddr en0 > "$DEST/packager-ip.txt" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make any sense to use a standard plist for this purpose instead of creating a txt file?
@frantic updated the pull request. |
Let's continue with #6362 |
Summary: Implemented automatic IP detection for iOS, based on facebook#6345 and facebook#6362. As the previous pull requests did, this works by writing the IP address of the host to a file. Closes facebook#8091 Differential Revision: D3427657 Pulled By: javache fbshipit-source-id: 3f534c9b32c4d6fb9615fc2e2c3c3aef421454c5
Summary: Implemented automatic IP detection for iOS, based on facebook#6345 and facebook#6362. As the previous pull requests did, this works by writing the IP address of the host to a file. Closes facebook#8091 Differential Revision: D3427657 Pulled By: javache fbshipit-source-id: 3f534c9b32c4d6fb9615fc2e2c3c3aef421454c5
Summary: Implemented automatic IP detection for iOS, based on facebook#6345 and facebook#6362. As the previous pull requests did, this works by writing the IP address of the host to a file. Closes facebook#8091 Differential Revision: D3427657 Pulled By: javache fbshipit-source-id: 3f534c9b32c4d6fb9615fc2e2c3c3aef421454c5
Did you ended up with a solution to this. Connection to the packager is very unstable on react-native@0.55.4. It can work for days and then fails randomly, it happens often and it's quite frustrating. Here is the complete Xcode log.
I have tried so many things I can't even remember all of them, here is what I've done:
I saw that you talked about a file DEST=$CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH
if [[ "$CONFIGURATION" = "Debug" && ! "$PLATFORM_NAME" == *simulator ]]; then
IP=$(ipconfig getifaddr en0)
if [ -z "$IP" ]; then
IP=$(ifconfig | grep 'inet ' | grep -v ' 127.' | cut -d\ -f2 | awk 'NR==1{print $1}')
fi
echo "$IP" > "$DEST/ip.txt"
fi The command used here do work on my bash and returns I don't know if it's related to this issue, but it happens from time to time that when I shake my phone, two menus are showing (still happening now that the app is running). Another strange warning just appeared today (even though I didn't change any package in my react-native project): One last thing, my application is using web socket, and my app just crashed before and some socket may not have been closed properly (once again, I don't know if this has any influence but I prefer to add too much information in here, just in case). Edit Ah, just a got new error (in Xcode):
I tried to re-attach it, and here is the message I got:
That reminds me one more thing, this all happened while my phone was plugged to my laptop (and my usb port is kind of rusty). |
I finally found the issue, it comes from my Firewall which for some reason started to block connection to my packager (OSX 10.12.6). I realised that when tried to manually get the bundle from my phone web browser using the address I feel like this happens because of a more complex rule than "blocking a port" or blocking an application", indeed, I restarted my Firewall and relaunched the packager and now it works (in the mean time I also restarted my packager as super user, not sure if this had any effect tho). This also explains why it stoped working all of a sudden and without any change to my project. |
I've been thinking a lot about the pain of configuring packager's IP address on the iOS side of React Native project. This is option 1 of 2.
Seems like the most common flow is to use packager for simulator and device builds in development and pre-bundled file in production. The most reliable option of distinguishing development/production environment is inspecting
DEBUG
in Xcode, it is defined for "Debug" build configuration and not defined for "Release" (we already rely on this in a bunch of other places). I think it's safe to assume this is the case and add#ifdef DEBUG
into generatedAppDelegate.m
by default. Important note here is that it doesn't hide this deep inside framework, just makes the most common case easier. Users can still rewrite logic aroundjsCodeLocation
to match their use case (e.g. CI builds).The second part of this diff is about automatically detecting packager's IP address. There is a script that runs as a part of every Xcode build called
react-native-xcode.sh
. We can use it to store developer's computer IP address to a file inside the app. We only need to do this for development builds of RN app for device. I've included a small helper function to read the IP address from that text file. This function can be helpful for figuring outjsCodeLocation
.And the last part – this PR makes
RCTWebSocketExecutor
use the same host/port as the corresponding bridge bundle URL. This means that by only settingjsCodeLocation
to point to correct location we can get Chrome debugger to work seamlessly without any additional hacks.Let me know if you'd prefer me to split these into 3 chunks, but I believe getting these 3 changes in will improve DX on iOS a lot.
Test plan
Patched
react-native-cli
on my machine to point to my local react-native checkout,react-native init TestProject
. Ran it on simulator and device, confirmed loading and Chrome debugging worked in both environments without andy additional configuration. Made sure pre-bundled file is used when Xcode "Build Configuration" is set to "Release".