Skip to content

Commit c24b5e9

Browse files
philIipfacebook-github-bot
authored andcommitted
decouple RCTHost bundleURL setter from delegate (#37566)
Summary: Pull Request resolved: #37566 Changelog: [Internal] in this diff stack, i remove `- (NSURL *)getBundleURL;` from the bridgeless API. the reason for this is because the bundle url does not change in the middle of an app session, unless for developer mode, so it's more robust for us to pass it as a dependency. at the end of the diff stack, i'll add an escape hatch that allows us to update the bundle url for our dev mode case, so we can delete the API. in this diff, i do some cleanup so the bundle logic is more reusable. Reviewed By: sammy-SC Differential Revision: D45937853 fbshipit-source-id: e80bacfa7342f63caa020e4a00750ffa156bf8e7
1 parent d4f6cf1 commit c24b5e9

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)