Add API for getting sourceURL directly from ReactContext

Summary:
In bridgeless mode, the CatalystInstance doesn't exist, but we still need to be able to access the sourceURL in SourceCodeModule (which is needed to render the images in LogBox warnings and errors). This diff adds a new API for getting the sourceURL directly from ReactContext, instead of having to call context.getCatalystInstance().getSourceURL(), and updates SourceCodeModule to use it.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D20848700

fbshipit-source-id: 3ecda81a17121178b76bbb3e9b0f27f103c1961a
This commit is contained in:
Emily Janzer
2020-04-06 11:37:14 -07:00
committed by Facebook GitHub Bot
parent 4cbcee7567
commit 9d56c07bea
2 changed files with 11 additions and 1 deletions
@@ -455,4 +455,14 @@ public class ReactContext extends ContextWrapper {
}
return mCatalystInstance.getJSIModule(moduleType);
}
/**
* Get the sourceURL for the JS bundle from the CatalystInstance. This method is needed for
* compatibility with bridgeless mode, which has no CatalystInstance.
*
* @return The JS bundle URL set when the bundle was loaded
*/
public @Nullable String getSourceURL() {
return mCatalystInstance.getSourceURL();
}
}
@@ -37,7 +37,7 @@ public class SourceCodeModule extends NativeSourceCodeSpec {
String sourceURL =
Assertions.assertNotNull(
getReactApplicationContext().getCatalystInstance().getSourceURL(),
getReactApplicationContext().getSourceURL(),
"No source URL loaded, have you initialised the instance?");
constants.put("scriptURL", sourceURL);