Skip to content

Commit fa785a1

Browse files
committed
Add feature flag to enable experimental MutationObserver (#55919)
Summary: Pull Request resolved: #55919 Changelog: [internal] Adds a new feature flag to enable the experimental and partial implementation of `MutationObserver` Reviewed By: Abbondanzo, sammy-SC, javache Differential Revision: D95223862 fbshipit-source-id: e19dd163e5f7fecd9ef28b79be61455f0993a3c4
1 parent 0004708 commit fa785a1

30 files changed

Lines changed: 288 additions & 65 deletions

packages/react-native/Package.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,13 @@ let reactIntersectionObserverNativeModule = RNTarget(
344344
dependencies: [.reactNativeDependencies, .reactCxxReact, .reactFabric, .reactTurboModuleBridging, .reactTurboModuleCore, .reactGraphics, .reactGraphicsApple, .reactRuntimeScheduler, .yoga]
345345
)
346346

347+
/// React-mutationobservernativemodule.podspec
348+
let reactMutationObserverNativeModule = RNTarget(
349+
name: .reactMutationObserverNativeModule,
350+
path: "ReactCommon/react/nativemodule/mutationobserver",
351+
dependencies: [.reactNativeDependencies, .reactCxxReact, .reactFabric, .reactTurboModuleBridging, .reactTurboModuleCore, .yoga]
352+
)
353+
347354
/// React-featureflagnativemodule.podspec
348355
let reactFeatureflagsNativemodule = RNTarget(
349356
name: .reactFeatureflagsNativemodule,
@@ -457,7 +464,7 @@ let reactFabric = RNTarget(
457464
"components/root/tests",
458465
],
459466
dependencies: [.reactNativeDependencies, .reactJsiExecutor, .rctTypesafety, .reactTurboModuleCore, .jsi, .logger, .reactDebug, .reactFeatureFlags, .reactUtils, .reactRuntimeScheduler, .reactCxxReact, .reactRendererDebug, .reactGraphics, .yoga],
460-
sources: ["animated", "animationbackend", "animations", "attributedstring", "core", "componentregistry", "componentregistry/native", "components/root", "components/view", "components/view/platform/cxx", "components/scrollview", "components/scrollview/platform/cxx", "components/scrollview/platform/ios", "components/legacyviewmanagerinterop", "components/legacyviewmanagerinterop/platform/ios", "dom", "scheduler", "mounting", "observers/events", "observers/intersection", "telemetry", "consistency", "leakchecker", "uimanager", "uimanager/consistency"]
467+
sources: ["animated", "animationbackend", "animations", "attributedstring", "core", "componentregistry", "componentregistry/native", "components/root", "components/view", "components/view/platform/cxx", "components/scrollview", "components/scrollview/platform/cxx", "components/scrollview/platform/ios", "components/legacyviewmanagerinterop", "components/legacyviewmanagerinterop/platform/ios", "dom", "scheduler", "mounting", "observers/events", "observers/intersection", "observers/mutation", "telemetry", "consistency", "leakchecker", "uimanager", "uimanager/consistency"]
461468
)
462469

463470
let reactFabricInputAccessory = RNTarget(
@@ -693,6 +700,7 @@ let targets = [
693700
reactIdleCallbacksNativeModule,
694701
reactWebPerformanceNativeModule,
695702
reactIntersectionObserverNativeModule,
703+
reactMutationObserverNativeModule,
696704
reactFeatureflagsNativemodule,
697705
reactNativeModuleDom,
698706
reactAppDelegate,
@@ -881,6 +889,7 @@ extension String {
881889
static let reactIdleCallbacksNativeModule = "React-idlecallbacksnativemodule"
882890
static let reactWebPerformanceNativeModule = "React-webperformancenativemodule"
883891
static let reactIntersectionObserverNativeModule = "React-intersectionobservernativemodule"
892+
static let reactMutationObserverNativeModule = "React-mutationobservernativemodule"
884893
static let reactFeatureflagsNativemodule = "React-featureflagsnativemodule"
885894
static let reactNativeModuleDom = "React-domnativemodule"
886895
static let reactAppDelegate = "React-RCTAppDelegate"

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<156d4f5f35037184b6fc61ff1d856028>>
7+
* @generated SignedSource<<891ad57e850a493d32fed3210a6a52bf>>
88
*/
99

1010
/**
@@ -276,6 +276,12 @@ public object ReactNativeFeatureFlags {
276276
@JvmStatic
277277
public fun enableModuleArgumentNSNullConversionIOS(): Boolean = accessor.enableModuleArgumentNSNullConversionIOS()
278278

279+
/**
280+
* Enables the MutationObserver Web API in React Native.
281+
*/
282+
@JvmStatic
283+
public fun enableMutationObserverByDefault(): Boolean = accessor.enableMutationObserverByDefault()
284+
279285
/**
280286
* Parse CSS strings using the Fabric CSS parser instead of ViewConfig processing
281287
*/

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<0875d5e54d884a26d37bb4eb2acc57d5>>
7+
* @generated SignedSource<<9cd9f7106e4538a23d8c9ea522ab0bb5>>
88
*/
99

1010
/**
@@ -61,6 +61,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
6161
private var enableLayoutAnimationsOnIOSCache: Boolean? = null
6262
private var enableMainQueueCoordinatorOnIOSCache: Boolean? = null
6363
private var enableModuleArgumentNSNullConversionIOSCache: Boolean? = null
64+
private var enableMutationObserverByDefaultCache: Boolean? = null
6465
private var enableNativeCSSParsingCache: Boolean? = null
6566
private var enableNetworkEventReportingCache: Boolean? = null
6667
private var enablePreparedTextLayoutCache: Boolean? = null
@@ -475,6 +476,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
475476
return cached
476477
}
477478

479+
override fun enableMutationObserverByDefault(): Boolean {
480+
var cached = enableMutationObserverByDefaultCache
481+
if (cached == null) {
482+
cached = ReactNativeFeatureFlagsCxxInterop.enableMutationObserverByDefault()
483+
enableMutationObserverByDefaultCache = cached
484+
}
485+
return cached
486+
}
487+
478488
override fun enableNativeCSSParsing(): Boolean {
479489
var cached = enableNativeCSSParsingCache
480490
if (cached == null) {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<948a9beebe2ff00791a03455eb774eee>>
7+
* @generated SignedSource<<c09b7b1e5fafe7be59026094e17a574c>>
88
*/
99

1010
/**
@@ -110,6 +110,8 @@ public object ReactNativeFeatureFlagsCxxInterop {
110110

111111
@DoNotStrip @JvmStatic public external fun enableModuleArgumentNSNullConversionIOS(): Boolean
112112

113+
@DoNotStrip @JvmStatic public external fun enableMutationObserverByDefault(): Boolean
114+
113115
@DoNotStrip @JvmStatic public external fun enableNativeCSSParsing(): Boolean
114116

115117
@DoNotStrip @JvmStatic public external fun enableNetworkEventReporting(): Boolean

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<89c61520177334f93c65ff92c2fc74a6>>
7+
* @generated SignedSource<<f022760e4cfc71de389cde1ecf1c0a79>>
88
*/
99

1010
/**
@@ -105,6 +105,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
105105

106106
override fun enableModuleArgumentNSNullConversionIOS(): Boolean = false
107107

108+
override fun enableMutationObserverByDefault(): Boolean = false
109+
108110
override fun enableNativeCSSParsing(): Boolean = false
109111

110112
override fun enableNetworkEventReporting(): Boolean = true

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<669708c311abe9ffc8f7783219e2baad>>
7+
* @generated SignedSource<<39ecd618d48689ae2a30d7648d560b89>>
88
*/
99

1010
/**
@@ -65,6 +65,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
6565
private var enableLayoutAnimationsOnIOSCache: Boolean? = null
6666
private var enableMainQueueCoordinatorOnIOSCache: Boolean? = null
6767
private var enableModuleArgumentNSNullConversionIOSCache: Boolean? = null
68+
private var enableMutationObserverByDefaultCache: Boolean? = null
6869
private var enableNativeCSSParsingCache: Boolean? = null
6970
private var enableNetworkEventReportingCache: Boolean? = null
7071
private var enablePreparedTextLayoutCache: Boolean? = null
@@ -520,6 +521,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
520521
return cached
521522
}
522523

524+
override fun enableMutationObserverByDefault(): Boolean {
525+
var cached = enableMutationObserverByDefaultCache
526+
if (cached == null) {
527+
cached = currentProvider.enableMutationObserverByDefault()
528+
accessedFeatureFlags.add("enableMutationObserverByDefault")
529+
enableMutationObserverByDefaultCache = cached
530+
}
531+
return cached
532+
}
533+
523534
override fun enableNativeCSSParsing(): Boolean {
524535
var cached = enableNativeCSSParsingCache
525536
if (cached == null) {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<db06b64a8d1b9ab99b368fea41185d62>>
7+
* @generated SignedSource<<9682cd769bcc7c53bf9999bbcb8e5573>>
88
*/
99

1010
/**
@@ -105,6 +105,8 @@ public interface ReactNativeFeatureFlagsProvider {
105105

106106
@DoNotStrip public fun enableModuleArgumentNSNullConversionIOS(): Boolean
107107

108+
@DoNotStrip public fun enableMutationObserverByDefault(): Boolean
109+
108110
@DoNotStrip public fun enableNativeCSSParsing(): Boolean
109111

110112
@DoNotStrip public fun enableNetworkEventReporting(): Boolean

packages/react-native/ReactAndroid/src/main/jni/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ add_react_common_subdir(react/renderer/components/safeareaview)
117117
add_react_common_subdir(react/renderer/leakchecker)
118118
add_react_common_subdir(react/renderer/observers/events)
119119
add_react_common_subdir(react/renderer/observers/intersection)
120+
add_react_common_subdir(react/renderer/observers/mutation)
120121
add_react_common_subdir(react/renderer/textlayoutmanager)
121122
add_react_common_subdir(react/utils)
122123
add_react_common_subdir(react/bridging)
@@ -128,6 +129,7 @@ add_react_common_subdir(react/nativemodule/featureflags)
128129
add_react_common_subdir(react/nativemodule/microtasks)
129130
add_react_common_subdir(react/nativemodule/idlecallbacks)
130131
add_react_common_subdir(react/nativemodule/intersectionobserver)
132+
add_react_common_subdir(react/nativemodule/mutationobserver)
131133
add_react_common_subdir(react/nativemodule/webperformance)
132134
add_react_common_subdir(react/networking)
133135
add_react_common_subdir(jserrorhandler)
@@ -197,6 +199,7 @@ add_library(reactnative
197199
$<TARGET_OBJECTS:react_nativemodule_idlecallbacks>
198200
$<TARGET_OBJECTS:react_nativemodule_intersectionobserver>
199201
$<TARGET_OBJECTS:react_nativemodule_microtasks>
202+
$<TARGET_OBJECTS:react_nativemodule_mutationobserver>
200203
$<TARGET_OBJECTS:react_nativemodule_webperformance>
201204
$<TARGET_OBJECTS:react_networking>
202205
$<TARGET_OBJECTS:react_newarchdefaults>
@@ -219,6 +222,7 @@ add_library(reactnative
219222
$<TARGET_OBJECTS:react_renderer_mounting>
220223
$<TARGET_OBJECTS:react_renderer_observers_events>
221224
$<TARGET_OBJECTS:react_renderer_observers_intersection>
225+
$<TARGET_OBJECTS:react_renderer_observers_mutation>
222226
$<TARGET_OBJECTS:react_renderer_runtimescheduler>
223227
$<TARGET_OBJECTS:react_renderer_scheduler>
224228
$<TARGET_OBJECTS:react_renderer_telemetry>
@@ -292,6 +296,7 @@ target_include_directories(reactnative
292296
$<TARGET_PROPERTY:react_nativemodule_idlecallbacks,INTERFACE_INCLUDE_DIRECTORIES>
293297
$<TARGET_PROPERTY:react_nativemodule_intersectionobserver,INTERFACE_INCLUDE_DIRECTORIES>
294298
$<TARGET_PROPERTY:react_nativemodule_microtasks,INTERFACE_INCLUDE_DIRECTORIES>
299+
$<TARGET_PROPERTY:react_nativemodule_mutationobserver,INTERFACE_INCLUDE_DIRECTORIES>
295300
$<TARGET_PROPERTY:react_nativemodule_webperformance,INTERFACE_INCLUDE_DIRECTORIES>
296301
$<TARGET_PROPERTY:react_networking,INTERFACE_INCLUDE_DIRECTORIES>
297302
$<TARGET_PROPERTY:react_newarchdefaults,INTERFACE_INCLUDE_DIRECTORIES>
@@ -315,6 +320,8 @@ target_include_directories(reactnative
315320
$<TARGET_PROPERTY:react_renderer_mapbuffer,INTERFACE_INCLUDE_DIRECTORIES>
316321
$<TARGET_PROPERTY:react_renderer_mounting,INTERFACE_INCLUDE_DIRECTORIES>
317322
$<TARGET_PROPERTY:react_renderer_observers_events,INTERFACE_INCLUDE_DIRECTORIES>
323+
$<TARGET_PROPERTY:react_renderer_observers_intersection,INTERFACE_INCLUDE_DIRECTORIES>
324+
$<TARGET_PROPERTY:react_renderer_observers_mutation,INTERFACE_INCLUDE_DIRECTORIES>
318325
$<TARGET_PROPERTY:react_renderer_runtimescheduler,INTERFACE_INCLUDE_DIRECTORIES>
319326
$<TARGET_PROPERTY:react_renderer_scheduler,INTERFACE_INCLUDE_DIRECTORIES>
320327
$<TARGET_PROPERTY:react_renderer_telemetry,INTERFACE_INCLUDE_DIRECTORIES>

packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<0b95d68522d63d51d3e524aeecff246a>>
7+
* @generated SignedSource<<864e786c3042a66447f589695db7aebc>>
88
*/
99

1010
/**
@@ -285,6 +285,12 @@ class ReactNativeFeatureFlagsJavaProvider
285285
return method(javaProvider_);
286286
}
287287

288+
bool enableMutationObserverByDefault() override {
289+
static const auto method =
290+
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableMutationObserverByDefault");
291+
return method(javaProvider_);
292+
}
293+
288294
bool enableNativeCSSParsing() override {
289295
static const auto method =
290296
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableNativeCSSParsing");
@@ -758,6 +764,11 @@ bool JReactNativeFeatureFlagsCxxInterop::enableModuleArgumentNSNullConversionIOS
758764
return ReactNativeFeatureFlags::enableModuleArgumentNSNullConversionIOS();
759765
}
760766

767+
bool JReactNativeFeatureFlagsCxxInterop::enableMutationObserverByDefault(
768+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
769+
return ReactNativeFeatureFlags::enableMutationObserverByDefault();
770+
}
771+
761772
bool JReactNativeFeatureFlagsCxxInterop::enableNativeCSSParsing(
762773
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
763774
return ReactNativeFeatureFlags::enableNativeCSSParsing();
@@ -1132,6 +1143,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
11321143
makeNativeMethod(
11331144
"enableModuleArgumentNSNullConversionIOS",
11341145
JReactNativeFeatureFlagsCxxInterop::enableModuleArgumentNSNullConversionIOS),
1146+
makeNativeMethod(
1147+
"enableMutationObserverByDefault",
1148+
JReactNativeFeatureFlagsCxxInterop::enableMutationObserverByDefault),
11351149
makeNativeMethod(
11361150
"enableNativeCSSParsing",
11371151
JReactNativeFeatureFlagsCxxInterop::enableNativeCSSParsing),

packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<6b7e2af51ba9d64ae4e474dfa104a7c3>>
7+
* @generated SignedSource<<2c9336f5ba6c40dfdec7137100d1fcc5>>
88
*/
99

1010
/**
@@ -153,6 +153,9 @@ class JReactNativeFeatureFlagsCxxInterop
153153
static bool enableModuleArgumentNSNullConversionIOS(
154154
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
155155

156+
static bool enableMutationObserverByDefault(
157+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
158+
156159
static bool enableNativeCSSParsing(
157160
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
158161

0 commit comments

Comments
 (0)