Skip to content

Commit

Permalink
add support to provide fallback-sourceURL: in case primary-sourceURL …
Browse files Browse the repository at this point in the history
…fails to load

Reviewed By: javache

Differential Revision: D3339692

fbshipit-source-id: 93fa1821bf4abca878832d4f75c6b9968d8d0460
  • Loading branch information
anoopc authored and Facebook Github Bot 3 committed May 25, 2016
1 parent 298dc7c commit 1586a32
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
13 changes: 12 additions & 1 deletion React/Base/RCTBatchedBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,18 @@ - (void)loadSource:(RCTSourceLoadBlock)_onSourceLoad
if ([self.delegate respondsToSelector:@selector(loadSourceForBridge:withBlock:)]) {
[self.delegate loadSourceForBridge:_parentBridge withBlock:onSourceLoad];
} else if (self.bundleURL) {
[RCTJavaScriptLoader loadBundleAtURL:self.bundleURL onComplete:onSourceLoad];
[RCTJavaScriptLoader loadBundleAtURL:self.bundleURL onComplete:^(NSError *error, NSData *source) {
if (error && [self.delegate respondsToSelector:@selector(fallbackSourceURLForBridge:)]) {
NSURL *fallbackURL = [self.delegate fallbackSourceURLForBridge:_parentBridge];
if (fallbackURL && ![fallbackURL isEqual:self.bundleURL]) {
RCTLogError(@"Failed to load bundle(%@) with error:(%@)", self.bundleURL, error.localizedDescription);
self.bundleURL = fallbackURL;
[RCTJavaScriptLoader loadBundleAtURL:self.bundleURL onComplete:onSourceLoad];
return;
}
}
onSourceLoad(error, source);
}];
} else {
// Allow testing without a script
dispatch_async(dispatch_get_main_queue(), ^{
Expand Down
9 changes: 9 additions & 0 deletions React/Base/RCTBridgeDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ typedef void (^RCTSourceLoadBlock)(NSError *error, NSData *source);

@optional

/**
* The bridge will attempt to load the JS source code from the location specified
* by the `sourceURLForBridge:` method, if loading fails, you can implement this
* method to specify fallbackSourceURL.
* NOTE: We don't plan to support this API permanently (this method will be
* removed after we track down why a valid sourceURL fails to load sometimes).
*/
- (NSURL *)fallbackSourceURLForBridge:(RCTBridge *)bridge;

/**
* The bridge initializes any registered RCTBridgeModules automatically, however
* if you wish to instantiate your own module instances, you can return them
Expand Down

0 comments on commit 1586a32

Please sign in to comment.