Skip to content

Commit

Permalink
introduce internal API to reload bridgeless without surface restart
Browse files Browse the repository at this point in the history
Summary:
Changelog: [Internal]

introducing an internal API to reload without starting up the surfaces that were stopped at time of reload

Differential Revision: D65461606
  • Loading branch information
philIip authored and facebook-github-bot committed Nov 5, 2024
1 parent 0e7ba90 commit 32b305b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
- (void)registerSegmentWithId:(NSNumber *)segmentId path:(NSString *)path;
- (void)setBundleURLProvider:(RCTHostBundleURLProvider)bundleURLProvider;
- (void)setContextContainerHandler:(id<RCTContextContainerHandling>)contextContainerHandler;
- (void)reload;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -282,25 +282,7 @@ - (void)callFunctionOnJSModule:(NSString *)moduleName method:(NSString *)method

- (void)didReceiveReloadCommand
{
[_instance invalidate];
_instance = nil;
if (_bundleURLProvider) {
[self _setBundleURL:_bundleURLProvider()];
}

_instance = [[RCTInstance alloc] initWithDelegate:self
jsRuntimeFactory:[self _provideJSEngine]
bundleManager:_bundleManager
turboModuleManagerDelegate:_turboModuleManagerDelegate
moduleRegistry:_moduleRegistry
parentInspectorTarget:_inspectorTarget.get()
launchOptions:_launchOptions];
[_hostDelegate hostDidStart:self];

for (RCTFabricSurface *surface in [self _getAttachedSurfaces]) {
[surface resetWithSurfacePresenter:self.surfacePresenter];
[_instance callFunctionOnBufferedRuntimeExecutor:[surface](facebook::jsi::Runtime &_) { [surface start]; }];
}
[self _reloadWithShouldRestartSurfaces:YES];
}

- (void)dealloc
Expand Down Expand Up @@ -383,6 +365,11 @@ - (void)setContextContainerHandler:(id<RCTContextContainerHandling>)contextConta
_contextContainerHandler = contextContainerHandler;
}

- (void)reload
{
[self _reloadWithShouldRestartSurfaces:NO];
}

#pragma mark - Private

- (void)_attachSurface:(RCTFabricSurface *)surface
Expand Down Expand Up @@ -427,6 +414,33 @@ - (void)_setBundleURL:(NSURL *)bundleURL
RCTReloadCommandSetBundleURL(_bundleURL);
}

- (void)_reloadWithShouldRestartSurfaces:(BOOL)shouldRestartSurfaces
{
[_instance invalidate];
_instance = nil;
if (_bundleURLProvider) {
[self _setBundleURL:_bundleURLProvider()];
}

_instance = [[RCTInstance alloc] initWithDelegate:self
jsRuntimeFactory:[self _provideJSEngine]
bundleManager:_bundleManager
turboModuleManagerDelegate:_turboModuleManagerDelegate
moduleRegistry:_moduleRegistry
parentInspectorTarget:_inspectorTarget.get()
launchOptions:_launchOptions];
[_hostDelegate hostDidStart:self];

for (RCTFabricSurface *surface in [self _getAttachedSurfaces]) {
[surface resetWithSurfacePresenter:self.surfacePresenter];
if (shouldRestartSurfaces) {
[_instance callFunctionOnBufferedRuntimeExecutor:[surface](facebook::jsi::Runtime &_) { [surface start]; }];
}
}
}

#pragma mark - jsinspector_modern

- (jsinspector_modern::HostTarget *)inspectorTarget
{
return _inspectorTarget.get();
Expand Down

0 comments on commit 32b305b

Please sign in to comment.