Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<01feab16132bc07b79b359178e322327>>
* @generated SignedSource<<862c5a78fec94408ca78ef2349627a02>>
*/

/**
Expand Down Expand Up @@ -372,6 +372,12 @@ public object ReactNativeFeatureFlags {
@JvmStatic
public fun fixMappingOfEventPrioritiesBetweenFabricAndReact(): Boolean = accessor.fixMappingOfEventPrioritiesBetweenFabricAndReact()

/**
* Enable system assertion validating that Fusebox is configured with a single host. When set, the CDP backend will dynamically disable features (Perf and Network) in the event that multiple hosts are registered (undefined behaviour), and broadcast this over `ReactNativeApplication.systemStateChanged`.
*/
@JvmStatic
public fun fuseboxAssertSingleHostState(): Boolean = accessor.fuseboxAssertSingleHostState()

/**
* Flag determining if the React Native DevTools (Fusebox) CDP backend should be enabled in release builds. This flag is global and should not be changed across React Host lifetimes.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<405bf283e4631e166cd57f5dfe30d5f9>>
* @generated SignedSource<<67b008ecdc29278a7019f60e24673fc1>>
*/

/**
Expand Down Expand Up @@ -77,6 +77,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
private var enableVirtualViewWindowFocusDetectionCache: Boolean? = null
private var enableWebPerformanceAPIsByDefaultCache: Boolean? = null
private var fixMappingOfEventPrioritiesBetweenFabricAndReactCache: Boolean? = null
private var fuseboxAssertSingleHostStateCache: Boolean? = null
private var fuseboxEnabledReleaseCache: Boolean? = null
private var fuseboxNetworkInspectionEnabledCache: Boolean? = null
private var hideOffscreenVirtualViewsOnIOSCache: Boolean? = null
Expand Down Expand Up @@ -618,6 +619,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
return cached
}

override fun fuseboxAssertSingleHostState(): Boolean {
var cached = fuseboxAssertSingleHostStateCache
if (cached == null) {
cached = ReactNativeFeatureFlagsCxxInterop.fuseboxAssertSingleHostState()
fuseboxAssertSingleHostStateCache = cached
}
return cached
}

override fun fuseboxEnabledRelease(): Boolean {
var cached = fuseboxEnabledReleaseCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<bffd645aa55b941acff92ca4efe6192a>>
* @generated SignedSource<<553d71b2c9e8e89b2e5d48723f3009b4>>
*/

/**
Expand Down Expand Up @@ -142,6 +142,8 @@ public object ReactNativeFeatureFlagsCxxInterop {

@DoNotStrip @JvmStatic public external fun fixMappingOfEventPrioritiesBetweenFabricAndReact(): Boolean

@DoNotStrip @JvmStatic public external fun fuseboxAssertSingleHostState(): Boolean

@DoNotStrip @JvmStatic public external fun fuseboxEnabledRelease(): Boolean

@DoNotStrip @JvmStatic public external fun fuseboxNetworkInspectionEnabled(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<a25d191472f7777804175ef9f56521d6>>
* @generated SignedSource<<bf1a3a96ae311f186f7fffacc466407e>>
*/

/**
Expand Down Expand Up @@ -137,6 +137,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi

override fun fixMappingOfEventPrioritiesBetweenFabricAndReact(): Boolean = false

override fun fuseboxAssertSingleHostState(): Boolean = true

override fun fuseboxEnabledRelease(): Boolean = false

override fun fuseboxNetworkInspectionEnabled(): Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<e8531e8c374d0ea1e604a2f3d5000078>>
* @generated SignedSource<<7a2517498558f2c0f69831d5466ddec3>>
*/

/**
Expand Down Expand Up @@ -81,6 +81,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
private var enableVirtualViewWindowFocusDetectionCache: Boolean? = null
private var enableWebPerformanceAPIsByDefaultCache: Boolean? = null
private var fixMappingOfEventPrioritiesBetweenFabricAndReactCache: Boolean? = null
private var fuseboxAssertSingleHostStateCache: Boolean? = null
private var fuseboxEnabledReleaseCache: Boolean? = null
private var fuseboxNetworkInspectionEnabledCache: Boolean? = null
private var hideOffscreenVirtualViewsOnIOSCache: Boolean? = null
Expand Down Expand Up @@ -679,6 +680,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
return cached
}

override fun fuseboxAssertSingleHostState(): Boolean {
var cached = fuseboxAssertSingleHostStateCache
if (cached == null) {
cached = currentProvider.fuseboxAssertSingleHostState()
accessedFeatureFlags.add("fuseboxAssertSingleHostState")
fuseboxAssertSingleHostStateCache = cached
}
return cached
}

override fun fuseboxEnabledRelease(): Boolean {
var cached = fuseboxEnabledReleaseCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<2325f5410537941e25998ca8c59bf51d>>
* @generated SignedSource<<0efef5db3ded62f312486ac2fb04bcdb>>
*/

/**
Expand Down Expand Up @@ -137,6 +137,8 @@ public interface ReactNativeFeatureFlagsProvider {

@DoNotStrip public fun fixMappingOfEventPrioritiesBetweenFabricAndReact(): Boolean

@DoNotStrip public fun fuseboxAssertSingleHostState(): Boolean

@DoNotStrip public fun fuseboxEnabledRelease(): Boolean

@DoNotStrip public fun fuseboxNetworkInspectionEnabled(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<95ebd4929bf0f98aa059ad4b8139f7b3>>
* @generated SignedSource<<09f32ad880a470e45d3e5ba67a6e5831>>
*/

/**
Expand Down Expand Up @@ -381,6 +381,12 @@ class ReactNativeFeatureFlagsJavaProvider
return method(javaProvider_);
}

bool fuseboxAssertSingleHostState() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("fuseboxAssertSingleHostState");
return method(javaProvider_);
}

bool fuseboxEnabledRelease() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("fuseboxEnabledRelease");
Expand Down Expand Up @@ -832,6 +838,11 @@ bool JReactNativeFeatureFlagsCxxInterop::fixMappingOfEventPrioritiesBetweenFabri
return ReactNativeFeatureFlags::fixMappingOfEventPrioritiesBetweenFabricAndReact();
}

bool JReactNativeFeatureFlagsCxxInterop::fuseboxAssertSingleHostState(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::fuseboxAssertSingleHostState();
}

bool JReactNativeFeatureFlagsCxxInterop::fuseboxEnabledRelease(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::fuseboxEnabledRelease();
Expand Down Expand Up @@ -1169,6 +1180,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
makeNativeMethod(
"fixMappingOfEventPrioritiesBetweenFabricAndReact",
JReactNativeFeatureFlagsCxxInterop::fixMappingOfEventPrioritiesBetweenFabricAndReact),
makeNativeMethod(
"fuseboxAssertSingleHostState",
JReactNativeFeatureFlagsCxxInterop::fuseboxAssertSingleHostState),
makeNativeMethod(
"fuseboxEnabledRelease",
JReactNativeFeatureFlagsCxxInterop::fuseboxEnabledRelease),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<155f615584a7738dc5b89205c2ecad8b>>
* @generated SignedSource<<414ebc294bc434bdf5f9eca094eac268>>
*/

/**
Expand Down Expand Up @@ -201,6 +201,9 @@ class JReactNativeFeatureFlagsCxxInterop
static bool fixMappingOfEventPrioritiesBetweenFabricAndReact(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool fuseboxAssertSingleHostState(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool fuseboxEnabledRelease(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

Expand Down
22 changes: 22 additions & 0 deletions packages/react-native/ReactCommon/jsinspector-modern/HostAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#ifdef REACT_NATIVE_DEBUGGER_ENABLED
#include "InspectorFlags.h"
#include "InspectorInterfaces.h"
#include "NetworkIOAgent.h"
#include "SessionState.h"
#include "TracingAgent.h"
Expand Down Expand Up @@ -216,6 +217,11 @@ class HostAgent::Impl final {
cdp::jsonNotification(
"ReactNativeApplication.metadataUpdated",
createHostMetadataPayload(hostMetadata_)));
auto& inspector = getInspectorInstance();
bool isSingleHost = inspector.getSystemState().registeredPagesCount <= 1;
if (!isSingleHost) {
emitSystemStateChanged(isSingleHost);
}

auto stashedTraceRecording =
targetController_.getDelegate()
Expand Down Expand Up @@ -374,6 +380,17 @@ class HostAgent::Impl final {
tracingAgent_.emitExternalTraceRecording(std::move(traceRecording));
}

void emitSystemStateChanged(bool isSingleHost) {
frontendChannel_(
cdp::jsonNotification(
"ReactNativeApplication.systemStateChanged",
folly::dynamic::object("isSingleHost", isSingleHost)));

if (!isSingleHost) {
frontendChannel_(cdp::jsonNotification("Network.disable"));
}
}

private:
enum class FuseboxClientType { Unknown, Fusebox, NonFusebox };

Expand Down Expand Up @@ -480,6 +497,7 @@ class HostAgent::Impl final {
}
void emitExternalTraceRecording(tracing::TraceRecordingState traceRecording) {
}
void emitSystemStateChanged(bool isSingleHost) {}
};

#endif // REACT_NATIVE_DEBUGGER_ENABLED
Expand Down Expand Up @@ -519,6 +537,10 @@ void HostAgent::emitExternalTraceRecording(
impl_->emitExternalTraceRecording(std::move(traceRecording));
}

void HostAgent::emitSystemStateChanged(bool isSingleHost) const {
impl_->emitSystemStateChanged(isSingleHost);
}

#pragma mark - Tracing

HostTracingAgent::HostTracingAgent(tracing::TraceRecordingState& state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ class HostAgent final {
*/
void emitExternalTraceRecording(tracing::TraceRecordingState traceRecording) const;

/**
* Emits a system state changed event when the number of ReactHost instances
* changes.
*/
void emitSystemStateChanged(bool isSingleHost) const;

private:
// We use the private implementation idiom to ensure this class has the same
// layout regardless of whether REACT_NATIVE_DEBUGGER_ENABLED is defined. The
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@ class JSINSPECTOR_EXPORT HostTarget : public EnableExecutorFromThis<HostTarget>
*/
void emitTraceRecordingForFirstFuseboxClient(tracing::TraceRecordingState traceRecording) const;

/**
* Emits a system state changed event to all active sessions.
*/
void emitSystemStateChanged(bool isSingleHost) const;

private:
/**
* Constructs a new HostTarget.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ InspectorFlags& InspectorFlags::getInstance() {
return instance;
}

bool InspectorFlags::getAssertSingleHostState() const {
return loadFlagsAndAssertUnchanged().assertSingleHostState;
}

bool InspectorFlags::getFuseboxEnabled() const {
if (fuseboxDisabledForTest_) {
return false;
Expand Down Expand Up @@ -48,6 +52,8 @@ void InspectorFlags::dangerouslyDisableFuseboxForTest() {
const InspectorFlags::Values& InspectorFlags::loadFlagsAndAssertUnchanged()
const {
InspectorFlags::Values newValues = {
.assertSingleHostState =
ReactNativeFeatureFlags::fuseboxAssertSingleHostState(),
.fuseboxEnabled =
#if defined(REACT_NATIVE_DEBUGGER_ENABLED)
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ class InspectorFlags {
public:
static InspectorFlags &getInstance();

/**
* Flag determining if the inspector backend should strictly assert that only
* a single host is registered.
*/
bool getAssertSingleHostState() const;

/**
* Flag determining if the modern CDP backend should be enabled.
*/
Expand Down Expand Up @@ -54,6 +60,7 @@ class InspectorFlags {

private:
struct Values {
bool assertSingleHostState;
bool fuseboxEnabled;
bool isProfilingBuild;
bool networkInspectionEnabled;
Expand Down
Loading
Loading