Please sign in to comment.
BREAKING - (Re)moving `JSBundleLoader.getSourceUrl()`
Summary: == What == Changing the `JSBundleLoader` API, to remove `String getSourceUrl()`, instead `JSBundleLoader.loadScript` now returns the source URL it loaded. This change has a knock-on effect: We can no longer populate `SourceCodeModule` when we construct it, because at that time, we do not know the source URL. In order to solve this I have made the following changes: - Added `CatalystInstance.getSourceURL()`, to return the source URL from the instance after the JS Bundle has been loaded, or `null` otherwise. - Removed `ReactInstanceManager.getSourceUrl()`, because its only purpose was to populate `SourceCodeModule`. - Also removed `ReactInstanceManager.getJSBundleFile()` because it was only being used in a test confirming that the `ReactInstanceManager` knew its bundle file as soon as it was constructed, which is no longer necessarily true. - Initialise `SourceCodeModule` with the `ReactContext` instance it belongs to. - Override `NativeModule.initialize()` in `SourceCodeModule` to fetch the source URL. When the `SourceCodeModule` is constructed, the context does not have a properly initialised `CatalystInstance`, but by the time we call initialise on it, the `ReactContext` has a `CatalystInstance` and that in turn has a source URL. == Why == The reason for this change is that it allows us to add implementations of `JSBundleLoader`, that cannot determine their source URL until after having performed a load successfully. In particular I plan to introduce `FallbackJSBundleLoader` which will try to load from multiple sources in sequence stopping after the first successful load. As load failures could happen for a variety of reasons, we can't know what the true source URL is without performing the load. Reviewed By: javache Differential Revision: D4398956 fbshipit-source-id: 51ff4e289c8723e9d242f23267181c775a6abe6f
- Loading branch information...
Showing with 44 additions and 61 deletions.
- +1 −1 ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java
- +0 −10 ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java
- +0 −18 ReactAndroid/src/main/java/com/facebook/react/XReactInstanceManagerImpl.java
- +9 −0 ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstance.java
- +8 −1 ReactAndroid/src/main/java/com/facebook/react/cxxbridge/CatalystInstanceImpl.java
- +9 −23 ReactAndroid/src/main/java/com/facebook/react/cxxbridge/JSBundleLoader.java
- +1 −5 ReactAndroid/src/main/java/com/facebook/react/cxxbridge/OptimizedJSBundleLoader.java
- +16 −3 ReactAndroid/src/main/java/com/facebook/react/modules/debug/SourceCodeModule.java