| #
d5087a6c |
| 20-May-2021 |
Łukasz Kosmaty <[email protected]> |
[dev-launcher] Fix app hanging on the splash screen on iOS. (#12971)
# Why
Closes ENG-1133.
I noticed that the app contains a weird file called `ip.txt`.
When you build your app with the eas,
[dev-launcher] Fix app hanging on the splash screen on iOS. (#12971)
# Why
Closes ENG-1133.
I noticed that the app contains a weird file called `ip.txt`.
When you build your app with the eas, it’ll contain an IP of the builder - that IP will be outside of your network.
Unfortunately, RN tries to ping this address:
https://github.com/facebook/react-native/blob/b67dc01d1d52a9d12a1b9c807f6f89dd8490131a/React/Base/RCTBundleURLProvider.mm#L105-L108
https://github.com/facebook/react-native/blob/b67dc01d1d52a9d12a1b9c807f6f89dd8490131a/React/Base/RCTBundleURLProvider.mm#L112-L115
We can't just remove this file, cause it's responsible for WebSocket connection with bundler. So we need to establish this connection single-handedly.
# How
Firstly, I ignored the `ip.txt` file by swizzling the `guessPackagerHost` method from `RCTBundleURLProvider` (https://github.com/expo/react-native/blob/85f6d8f2b00f72ee18cedef2052471ae16c34e26/React/Base/RCTBundleURLProvider.m#L96-L112).
After that, the app won't be stuck on the splash screen anymore, but the WebSocket connection won't be available either.
To fix the socket connection, I chose a similar solution to the one from our fork (https://github.com/expo/react-native/blob/85f6d8f2b00f72ee18cedef2052471ae16c34e26/React/DevSupport/RCTPackagerConnection.mm#L151-L164) - set the URL in `EXDevLauncherController`. Sadly there is one more caveat - to do it, we need to have access to the `_mutex` variable from the `RCTPackagerConnection` class (https://github.com/expo/react-native/blob/85f6d8f2b00f72ee18cedef2052471ae16c34e26/React/DevSupport/RCTPackagerConnection.mm#L40). This variable is private and comes from cpp. Normally, we could use `valueForKey` to get such a variable, but not in that case (`valueForKey` will crash because it's coming from cpp!). The other solution that I found is to use `object_getInstanceVariable`. This function isn't normally available. To use it, you need to disable ARC. So that's what I did (only for one file).
I confirmed that the socket connection is working and the `RCTReconnectingWebSocket` is released (ensured that we don't have any leaks).
# Test Plan
- bare-expo ✅
show more ...
|