Skip to content

Commit cc727a2

Browse files
philIipfacebook-github-bot
authored andcommitted
introduce a private API to update the bundle url
Differential Revision: D45937853 fbshipit-source-id: 9415fe45221045c3f8e1a34331a2984b23a095ae
1 parent d4f6cf1 commit cc727a2

File tree

1 file changed

+19
-22
lines changed
  • packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core

1 file changed

+19
-22
lines changed

packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost.mm

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,7 @@ - (instancetype)initWithHostDelegate:(id<RCTHostDelegate>)hostDelegate
7979
};
8080

8181
auto bundleURLSetter = ^(NSURL *bundleURL) {
82-
RCTHost *strongSelf = weakSelf;
83-
if (!strongSelf) {
84-
return;
85-
}
86-
strongSelf->_bundleURL = bundleURL;
82+
[weakSelf _setBundleURL:bundleURL];
8783
};
8884

8985
auto defaultBundleURLGetter = ^NSURL *()
@@ -144,8 +140,7 @@ - (void)start
144140
@"RCTHost should not be creating a new instance if one already exists. This implies there is a bug with how/when this method is being called.");
145141
[_instance invalidate];
146142
}
147-
[self _refreshBundleURL];
148-
RCTReloadCommandSetBundleURL(_bundleURL);
143+
[self _setBundleURL:[_hostDelegate getBundleURL]];
149144
_instance = [[RCTInstance alloc] initWithDelegate:self
150145
jsEngineInstance:[self _provideJSEngine]
151146
bundleManager:_bundleManager
@@ -204,8 +199,7 @@ - (void)didReceiveReloadCommand
204199
{
205200
[_instance invalidate];
206201
_instance = nil;
207-
[self _refreshBundleURL];
208-
RCTReloadCommandSetBundleURL(_bundleURL);
202+
[self _setBundleURL:[_hostDelegate getBundleURL]];
209203

210204
// Ensure all attached surfaces are restarted after reload
211205
{
@@ -272,19 +266,6 @@ - (void)registerSegmentWithId:(NSNumber *)segmentId path:(NSString *)path
272266

273267
#pragma mark - Private
274268

275-
- (void)_refreshBundleURL FB_OBJC_DIRECT
276-
{
277-
// Reset the _bundleURL ivar if the RCTHost delegate presents a new bundleURL
278-
NSURL *newDelegateBundleURL = [_hostDelegate getBundleURL];
279-
if (newDelegateBundleURL && ![newDelegateBundleURL isEqual:_oldDelegateBundleURL]) {
280-
_oldDelegateBundleURL = newDelegateBundleURL;
281-
_bundleURL = newDelegateBundleURL;
282-
}
283-
284-
// Sanitize the bundle URL
285-
_bundleURL = [RCTConvert NSURL:_bundleURL.absoluteString];
286-
}
287-
288269
- (void)_attachSurface:(RCTFabricSurface *)surface FB_OBJC_DIRECT
289270
{
290271
_attachedSurfaces.push_back(surface);
@@ -311,4 +292,20 @@ - (void)_attachSurface:(RCTFabricSurface *)surface FB_OBJC_DIRECT
311292
return jsEngine;
312293
}
313294

295+
- (void)_setBundleURL:(NSURL *)bundleURL
296+
{
297+
// Reset the _bundleURL ivar if the RCTHost delegate presents a new bundleURL
298+
NSURL *newDelegateBundleURL = bundleURL;
299+
if (newDelegateBundleURL && ![newDelegateBundleURL isEqual:_oldDelegateBundleURL]) {
300+
_oldDelegateBundleURL = newDelegateBundleURL;
301+
_bundleURL = newDelegateBundleURL;
302+
}
303+
304+
// Sanitize the bundle URL
305+
_bundleURL = [RCTConvert NSURL:_bundleURL.absoluteString];
306+
307+
// Update the global bundle URLq
308+
RCTReloadCommandSetBundleURL(_bundleURL);
309+
}
310+
314311
@end

0 commit comments

Comments
 (0)