Skip to content

Commit 5ef6f97

Browse files
authored
Add feature flag to enable experimental MutationObserver (#55919) (#56597)
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 3770421 commit 5ef6f97

30 files changed

Lines changed: 297 additions & 74 deletions

packages/react-native/Package.swift

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

350+
/// React-mutationobservernativemodule.podspec
351+
let reactMutationObserverNativeModule = RNTarget(
352+
name: .reactMutationObserverNativeModule,
353+
path: "ReactCommon/react/nativemodule/mutationobserver",
354+
dependencies: [.reactNativeDependencies, .reactCxxReact, .reactFabric, .reactTurboModuleBridging, .reactTurboModuleCore, .yoga]
355+
)
356+
350357
/// React-featureflagnativemodule.podspec
351358
let reactFeatureflagsNativemodule = RNTarget(
352359
name: .reactFeatureflagsNativemodule,
@@ -463,7 +470,7 @@ let reactFabric = RNTarget(
463470
"components/root/tests",
464471
],
465472
dependencies: [.reactNativeDependencies, .reactJsiExecutor, .rctTypesafety, .reactTurboModuleCore, .jsi, .logger, .reactDebug, .reactFeatureFlags, .reactUtils, .reactRuntimeScheduler, .reactCxxReact, .reactRendererDebug, .reactGraphics, .yoga],
466-
sources: ["animations", "attributedstring", "core", "componentregistry", "componentregistry/native", "components/root", "components/view", "components/view/platform/cxx", "components/scrollview", "components/scrollview/platform/cxx", "components/legacyviewmanagerinterop", "dom", "scheduler", "mounting", "observers/events", "observers/intersection", "telemetry", "consistency", "leakchecker", "uimanager", "uimanager/consistency"]
473+
sources: ["animations", "attributedstring", "core", "componentregistry", "componentregistry/native", "components/root", "components/view", "components/view/platform/cxx", "components/scrollview", "components/scrollview/platform/cxx", "components/legacyviewmanagerinterop", "dom", "scheduler", "mounting", "observers/events", "observers/intersection", "observers/mutation", "telemetry", "consistency", "leakchecker", "uimanager", "uimanager/consistency"]
467474
)
468475

469476
let reactFabricInputAccessory = RNTarget(
@@ -699,6 +706,7 @@ let targets = [
699706
reactIdleCallbacksNativeModule,
700707
reactWebPerformanceNativeModule,
701708
reactIntersectionObserverNativeModule,
709+
reactMutationObserverNativeModule,
702710
reactFeatureflagsNativemodule,
703711
reactNativeModuleDom,
704712
reactAppDelegate,
@@ -887,6 +895,7 @@ extension String {
887895
static let reactIdleCallbacksNativeModule = "React-idlecallbacksnativemodule"
888896
static let reactWebPerformanceNativeModule = "React-webperformancenativemodule"
889897
static let reactIntersectionObserverNativeModule = "React-intersectionobservernativemodule"
898+
static let reactMutationObserverNativeModule = "React-mutationobservernativemodule"
890899
static let reactFeatureflagsNativemodule = "React-featureflagsnativemodule"
891900
static let reactNativeModuleDom = "React-domnativemodule"
892901
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<<26dfce17f8149372c967e83a1e55b497>>
7+
* @generated SignedSource<<b700a02133f84260647574d2f7a0f165>>
88
*/
99

1010
/**
@@ -246,6 +246,12 @@ public object ReactNativeFeatureFlags {
246246
@JvmStatic
247247
public fun enableModuleArgumentNSNullConversionIOS(): Boolean = accessor.enableModuleArgumentNSNullConversionIOS()
248248

249+
/**
250+
* Enables the MutationObserver Web API in React Native.
251+
*/
252+
@JvmStatic
253+
public fun enableMutationObserverByDefault(): Boolean = accessor.enableMutationObserverByDefault()
254+
249255
/**
250256
* Parse CSS strings using the Fabric CSS parser instead of ViewConfig processing
251257
*/

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<<7523b02820a1f77c0a851ed051770f51>>
7+
* @generated SignedSource<<d9309c7f772c314b78b329e5d1ad7216>>
88
*/
99

1010
/**
@@ -56,6 +56,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
5656
private var enableLayoutAnimationsOnIOSCache: Boolean? = null
5757
private var enableMainQueueCoordinatorOnIOSCache: Boolean? = null
5858
private var enableModuleArgumentNSNullConversionIOSCache: Boolean? = null
59+
private var enableMutationObserverByDefaultCache: Boolean? = null
5960
private var enableNativeCSSParsingCache: Boolean? = null
6061
private var enableNetworkEventReportingCache: Boolean? = null
6162
private var enablePreparedTextLayoutCache: Boolean? = null
@@ -434,6 +435,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
434435
return cached
435436
}
436437

438+
override fun enableMutationObserverByDefault(): Boolean {
439+
var cached = enableMutationObserverByDefaultCache
440+
if (cached == null) {
441+
cached = ReactNativeFeatureFlagsCxxInterop.enableMutationObserverByDefault()
442+
enableMutationObserverByDefaultCache = cached
443+
}
444+
return cached
445+
}
446+
437447
override fun enableNativeCSSParsing(): Boolean {
438448
var cached = enableNativeCSSParsingCache
439449
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<<0fa0febd40941c466222d1af82f677cf>>
7+
* @generated SignedSource<<1081d2d4673967a11e8f9ac287c89f02>>
88
*/
99

1010
/**
@@ -100,6 +100,8 @@ public object ReactNativeFeatureFlagsCxxInterop {
100100

101101
@DoNotStrip @JvmStatic public external fun enableModuleArgumentNSNullConversionIOS(): Boolean
102102

103+
@DoNotStrip @JvmStatic public external fun enableMutationObserverByDefault(): Boolean
104+
103105
@DoNotStrip @JvmStatic public external fun enableNativeCSSParsing(): Boolean
104106

105107
@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<<9158a8f1750ec5e9e530399fe09f52cf>>
7+
* @generated SignedSource<<bc4cd6eafbf14cd91755900db1956238>>
88
*/
99

1010
/**
@@ -95,6 +95,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
9595

9696
override fun enableModuleArgumentNSNullConversionIOS(): Boolean = false
9797

98+
override fun enableMutationObserverByDefault(): Boolean = false
99+
98100
override fun enableNativeCSSParsing(): Boolean = false
99101

100102
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<<9feb91e31a7d54e4b3f7737fb524800b>>
7+
* @generated SignedSource<<6deac57c7f55d6d7406f7dffb1abe487>>
88
*/
99

1010
/**
@@ -60,6 +60,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
6060
private var enableLayoutAnimationsOnIOSCache: Boolean? = null
6161
private var enableMainQueueCoordinatorOnIOSCache: Boolean? = null
6262
private var enableModuleArgumentNSNullConversionIOSCache: Boolean? = null
63+
private var enableMutationObserverByDefaultCache: Boolean? = null
6364
private var enableNativeCSSParsingCache: Boolean? = null
6465
private var enableNetworkEventReportingCache: Boolean? = null
6566
private var enablePreparedTextLayoutCache: Boolean? = null
@@ -474,6 +475,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
474475
return cached
475476
}
476477

478+
override fun enableMutationObserverByDefault(): Boolean {
479+
var cached = enableMutationObserverByDefaultCache
480+
if (cached == null) {
481+
cached = currentProvider.enableMutationObserverByDefault()
482+
accessedFeatureFlags.add("enableMutationObserverByDefault")
483+
enableMutationObserverByDefaultCache = cached
484+
}
485+
return cached
486+
}
487+
477488
override fun enableNativeCSSParsing(): Boolean {
478489
var cached = enableNativeCSSParsingCache
479490
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<<5425bfe01cb2aaecc61b65b8c2f7dad0>>
7+
* @generated SignedSource<<99e9d1149773ffdb867c2abed02b0302>>
88
*/
99

1010
/**
@@ -95,6 +95,8 @@ public interface ReactNativeFeatureFlagsProvider {
9595

9696
@DoNotStrip public fun enableModuleArgumentNSNullConversionIOS(): Boolean
9797

98+
@DoNotStrip public fun enableMutationObserverByDefault(): Boolean
99+
98100
@DoNotStrip public fun enableNativeCSSParsing(): Boolean
99101

100102
@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
@@ -115,6 +115,7 @@ add_react_common_subdir(react/renderer/components/safeareaview)
115115
add_react_common_subdir(react/renderer/leakchecker)
116116
add_react_common_subdir(react/renderer/observers/events)
117117
add_react_common_subdir(react/renderer/observers/intersection)
118+
add_react_common_subdir(react/renderer/observers/mutation)
118119
add_react_common_subdir(react/renderer/textlayoutmanager)
119120
add_react_common_subdir(react/utils)
120121
add_react_common_subdir(react/bridging)
@@ -126,6 +127,7 @@ add_react_common_subdir(react/nativemodule/featureflags)
126127
add_react_common_subdir(react/nativemodule/microtasks)
127128
add_react_common_subdir(react/nativemodule/idlecallbacks)
128129
add_react_common_subdir(react/nativemodule/intersectionobserver)
130+
add_react_common_subdir(react/nativemodule/mutationobserver)
129131
add_react_common_subdir(react/nativemodule/webperformance)
130132
add_react_common_subdir(react/networking)
131133
add_react_common_subdir(jserrorhandler)
@@ -195,6 +197,7 @@ add_library(reactnative
195197
$<TARGET_OBJECTS:react_nativemodule_idlecallbacks>
196198
$<TARGET_OBJECTS:react_nativemodule_intersectionobserver>
197199
$<TARGET_OBJECTS:react_nativemodule_microtasks>
200+
$<TARGET_OBJECTS:react_nativemodule_mutationobserver>
198201
$<TARGET_OBJECTS:react_nativemodule_webperformance>
199202
$<TARGET_OBJECTS:react_networking>
200203
$<TARGET_OBJECTS:react_newarchdefaults>
@@ -215,6 +218,7 @@ add_library(reactnative
215218
$<TARGET_OBJECTS:react_renderer_mounting>
216219
$<TARGET_OBJECTS:react_renderer_observers_events>
217220
$<TARGET_OBJECTS:react_renderer_observers_intersection>
221+
$<TARGET_OBJECTS:react_renderer_observers_mutation>
218222
$<TARGET_OBJECTS:react_renderer_runtimescheduler>
219223
$<TARGET_OBJECTS:react_renderer_scheduler>
220224
$<TARGET_OBJECTS:react_renderer_telemetry>
@@ -288,6 +292,7 @@ target_include_directories(reactnative
288292
$<TARGET_PROPERTY:react_nativemodule_idlecallbacks,INTERFACE_INCLUDE_DIRECTORIES>
289293
$<TARGET_PROPERTY:react_nativemodule_intersectionobserver,INTERFACE_INCLUDE_DIRECTORIES>
290294
$<TARGET_PROPERTY:react_nativemodule_microtasks,INTERFACE_INCLUDE_DIRECTORIES>
295+
$<TARGET_PROPERTY:react_nativemodule_mutationobserver,INTERFACE_INCLUDE_DIRECTORIES>
291296
$<TARGET_PROPERTY:react_nativemodule_webperformance,INTERFACE_INCLUDE_DIRECTORIES>
292297
$<TARGET_PROPERTY:react_networking,INTERFACE_INCLUDE_DIRECTORIES>
293298
$<TARGET_PROPERTY:react_newarchdefaults,INTERFACE_INCLUDE_DIRECTORIES>
@@ -309,6 +314,8 @@ target_include_directories(reactnative
309314
$<TARGET_PROPERTY:react_renderer_mapbuffer,INTERFACE_INCLUDE_DIRECTORIES>
310315
$<TARGET_PROPERTY:react_renderer_mounting,INTERFACE_INCLUDE_DIRECTORIES>
311316
$<TARGET_PROPERTY:react_renderer_observers_events,INTERFACE_INCLUDE_DIRECTORIES>
317+
$<TARGET_PROPERTY:react_renderer_observers_intersection,INTERFACE_INCLUDE_DIRECTORIES>
318+
$<TARGET_PROPERTY:react_renderer_observers_mutation,INTERFACE_INCLUDE_DIRECTORIES>
312319
$<TARGET_PROPERTY:react_renderer_runtimescheduler,INTERFACE_INCLUDE_DIRECTORIES>
313320
$<TARGET_PROPERTY:react_renderer_scheduler,INTERFACE_INCLUDE_DIRECTORIES>
314321
$<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<<986de1b799ad8bc22a323365aef3533b>>
7+
* @generated SignedSource<<9e684659117f413b92bcd0469fae37ba>>
88
*/
99

1010
/**
@@ -255,6 +255,12 @@ class ReactNativeFeatureFlagsJavaProvider
255255
return method(javaProvider_);
256256
}
257257

258+
bool enableMutationObserverByDefault() override {
259+
static const auto method =
260+
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableMutationObserverByDefault");
261+
return method(javaProvider_);
262+
}
263+
258264
bool enableNativeCSSParsing() override {
259265
static const auto method =
260266
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableNativeCSSParsing");
@@ -757,6 +763,11 @@ bool JReactNativeFeatureFlagsCxxInterop::enableModuleArgumentNSNullConversionIOS
757763
return ReactNativeFeatureFlags::enableModuleArgumentNSNullConversionIOS();
758764
}
759765

766+
bool JReactNativeFeatureFlagsCxxInterop::enableMutationObserverByDefault(
767+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
768+
return ReactNativeFeatureFlags::enableMutationObserverByDefault();
769+
}
770+
760771
bool JReactNativeFeatureFlagsCxxInterop::enableNativeCSSParsing(
761772
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
762773
return ReactNativeFeatureFlags::enableNativeCSSParsing();
@@ -1161,6 +1172,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
11611172
makeNativeMethod(
11621173
"enableModuleArgumentNSNullConversionIOS",
11631174
JReactNativeFeatureFlagsCxxInterop::enableModuleArgumentNSNullConversionIOS),
1175+
makeNativeMethod(
1176+
"enableMutationObserverByDefault",
1177+
JReactNativeFeatureFlagsCxxInterop::enableMutationObserverByDefault),
11641178
makeNativeMethod(
11651179
"enableNativeCSSParsing",
11661180
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<<f5aa0f101192f55b7ac12705d7667424>>
7+
* @generated SignedSource<<bf1f3b156e29c081684a9bada7e81a4b>>
88
*/
99

1010
/**
@@ -138,6 +138,9 @@ class JReactNativeFeatureFlagsCxxInterop
138138
static bool enableModuleArgumentNSNullConversionIOS(
139139
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
140140

141+
static bool enableMutationObserverByDefault(
142+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
143+
141144
static bool enableNativeCSSParsing(
142145
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
143146

0 commit comments

Comments
 (0)