Skip to content

Commit

Permalink
Register RCTBridge with modern CDP backend (#42394)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #42394

Changelog: [Internal][iOS] - Enable stub modern CDP backend in Bridge behind a feature flag

Minimally integrates the stub native CDP backend implementation (D50936932) into iOS Bridge.

This integration registers itself as a "Modern" target (D50967794, D50967795) to instruct `inspector-proxy` to disable its CDP hacks related to source map fetching, reloads, etc. This gives us a mostly-clean slate on which to develop and test native CDP functionality.

Reviewed By: huntie

Differential Revision: D50951138

fbshipit-source-id: 8c5ad9207e73265595884380c91e38f8d0ead84d
  • Loading branch information
motiz88 authored and facebook-github-bot committed Jan 22, 2024
1 parent 8a4c853 commit 9003d08
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/react-native/React-Core.podspec
Expand Up @@ -95,6 +95,8 @@ Pod::Spec.new do |s|
end
ss.exclude_files = exclude_files
ss.private_header_files = "React/Cxx*/*.h"

ss.dependency "React-jsinspector", version
end

s.subspec "DevSupport" do |ss|
Expand Down
35 changes: 35 additions & 0 deletions packages/react-native/React/Base/RCTBridge.mm
Expand Up @@ -14,6 +14,10 @@
#if RCT_ENABLE_INSPECTOR
#import "RCTInspectorDevServerHelper.h"
#endif
#import <jsinspector-modern/InspectorFlags.h>
#import <jsinspector-modern/InspectorInterfaces.h>
#import <jsinspector-modern/ReactCdp.h>
#import <optional>
#import "RCTDevLoadingViewProtocol.h"
#import "RCTJSThread.h"
#import "RCTLog.h"
Expand Down Expand Up @@ -189,6 +193,9 @@ @interface RCTBridge () <RCTReloadListener>

@implementation RCTBridge {
NSURL *_delegateBundleURL;

std::unique_ptr<facebook::react::jsinspector_modern::PageTarget> _inspectorTarget;
std::optional<int> _inspectorPageId;
}

+ (void)initialize
Expand Down Expand Up @@ -252,6 +259,11 @@ - (void)dealloc
* RCTAssertMainQueue();
*/
[self invalidate];
if (_inspectorPageId.has_value()) {
facebook::react::jsinspector_modern::getInspectorInstance().removePage(*_inspectorPageId);
_inspectorPageId.reset();
_inspectorTarget.reset();
}
}

- (void)setRCTTurboModuleRegistry:(id<RCTTurboModuleRegistry>)turboModuleRegistry
Expand Down Expand Up @@ -377,6 +389,29 @@ - (void)setUp
[_performanceLogger markStartForTag:RCTPLBridgeStartup];
[_performanceLogger markStartForTag:RCTPLTTI];

auto &inspectorFlags = facebook::react::jsinspector_modern::InspectorFlags::getInstance();
if (inspectorFlags.getEnableModernCDPRegistry() && !_inspectorPageId.has_value()) {
_inspectorTarget = std::make_unique<facebook::react::jsinspector_modern::PageTarget>();
__weak RCTBridge *weakSelf = self;
_inspectorPageId = facebook::react::jsinspector_modern::getInspectorInstance().addPage(
"React Native Bridge (Experimental)",
/* vm */ "",
[weakSelf](std::unique_ptr<facebook::react::jsinspector_modern::IRemoteConnection> remote)
-> std::unique_ptr<facebook::react::jsinspector_modern::ILocalConnection> {
RCTBridge *strongSelf = weakSelf;
if (!strongSelf) {
// This can happen if we're about to be dealloc'd. Reject the connection.
return nullptr;
}
return strongSelf->_inspectorTarget->connect(
std::move(remote),
{
.integrationName = "iOS Bridge (RCTBridge)",
});
},
facebook::react::jsinspector_modern::InspectorPageType::Modern);
}

Class bridgeClass = self.bridgeClass;

// Only update bundleURL from delegate if delegate bundleURL has changed
Expand Down

0 comments on commit 9003d08

Please sign in to comment.