-
Notifications
You must be signed in to change notification settings - Fork 946
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
Issue-1473: App Crash with Invalid scriptURL #1476
Changes from 2 commits
4beeb2d
a4619bd
ff96fe2
b63fe4f
00571e1
1fa045e
e74153f
c3940d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,13 +33,15 @@ let tempClientId: string | null = null | |
* | ||
* On an Android emulator, if you want to connect any servers of local, you will need run adb reverse on your terminal. This function gets the localhost IP of host machine directly to bypass this. | ||
*/ | ||
const getHost = (defaultHost = "localhost") => | ||
typeof NativeModules?.SourceCode?.getConstants().scriptURL === "string" // type guard in case this ever breaks https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/NativeModules/specs/NativeSourceCode.js#L15-L21 | ||
? NativeModules.SourceCode.scriptURL // Example: 'http://192.168.0.100:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.helloworld' | ||
.split("://")[1] // Remove the scheme: '192.168.0.100:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.helloworld' | ||
.split("/")[0] // Remove the path: '192.168.0.100:8081' | ||
.split(":")[0] // Remove the port: '192.168.0.100' | ||
: defaultHost | ||
const getHost = (defaultHost = "localhost") => { | ||
try { | ||
// RN Reference: https://github.com/facebook/react-native/blob/main/packages/react-native/src/private/specs/modules/NativeSourceCode.js | ||
return new URL(NativeModules?.SourceCode?.getConstants().scriptURL).hostname | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't see any reason not to use URL class here for this purpose: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC Hermes URL implementation has some problems. Josh has commented on this: facebook/hermes#1072 (comment). I'm not sure of the current state, but looking... From https://www.npmjs.com/package/react-native-url-polyfill, they claim it doesn't work with 'localhost' properly (facebook/react-native#26019), and creating new URLs can throw exceptions (facebook/react-native#16434). I think if we take this route we need to be sure to test it with a non-Expo app, since as that discussion mentions they added their own polyfill. Maybe test the oldest supported RN version too in case changes have been made that I haven't seen. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was unable to use the same package that Expo is using for their URL Here's the scoop: We use rollup for building the core dependencies into the packages like I could install that package in any other application, but not for use in our monorepo because of rollup... but I didn't figure that out until this morning because after I removed it... So I was then trying to figure out what cache is not being cleared. (I didn't realize rollup was involved.) Come to find out that I believe the nx cache is cleared when you switch branches and code changes in that dep. So in order for me to reliably add that package and not foobar the build I would have to run I have updated our I moved this to being a regex for now until we can do the prerequisite Rollup upgrades. |
||
} catch (error) { | ||
console.warn(`getHost: "${error.message}" for scriptURL - Falling back to ${defaultHost}`) | ||
return defaultHost | ||
} | ||
} | ||
|
||
const DEFAULTS: ClientOptions<ReactotronReactNative> = { | ||
createSocket: (path: string) => new WebSocket(path), // eslint-disable-line | ||
|
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.
This URL gives you more context as to what's available with this native module. I can change it back to the old link if that's more clear.