Skip to content

Commit 3057e28

Browse files
rubennortemeta-codesync[bot]
authored andcommitted
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 5ba0a1b commit 3057e28

30 files changed

Lines changed: 290 additions & 67 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", "viewtransition"]
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", "viewtransition"]
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<<66d3b8ed600077a287d6d7d8f6230b7b>>
7+
* @generated SignedSource<<55bcfe664afd673f0a9767468a3ca98f>>
88
*/
99

1010
/**
@@ -282,6 +282,12 @@ public object ReactNativeFeatureFlags {
282282
@JvmStatic
283283
public fun enableModuleArgumentNSNullConversionIOS(): Boolean = accessor.enableModuleArgumentNSNullConversionIOS()
284284

285+
/**
286+
* Enables the MutationObserver Web API in React Native.
287+
*/
288+
@JvmStatic
289+
public fun enableMutationObserverByDefault(): Boolean = accessor.enableMutationObserverByDefault()
290+
285291
/**
286292
* Parse CSS strings using the Fabric CSS parser instead of ViewConfig processing
287293
*/

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<<98c5f6184864381e579a9df82741928b>>
7+
* @generated SignedSource<<5ec50a8b4d2627a478ec9633e84ab046>>
88
*/
99

1010
/**
@@ -62,6 +62,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
6262
private var enableLayoutAnimationsOnIOSCache: Boolean? = null
6363
private var enableMainQueueCoordinatorOnIOSCache: Boolean? = null
6464
private var enableModuleArgumentNSNullConversionIOSCache: Boolean? = null
65+
private var enableMutationObserverByDefaultCache: Boolean? = null
6566
private var enableNativeCSSParsingCache: Boolean? = null
6667
private var enableNativeViewPropTransformationsCache: Boolean? = null
6768
private var enableNetworkEventReportingCache: Boolean? = null
@@ -487,6 +488,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
487488
return cached
488489
}
489490

491+
override fun enableMutationObserverByDefault(): Boolean {
492+
var cached = enableMutationObserverByDefaultCache
493+
if (cached == null) {
494+
cached = ReactNativeFeatureFlagsCxxInterop.enableMutationObserverByDefault()
495+
enableMutationObserverByDefaultCache = cached
496+
}
497+
return cached
498+
}
499+
490500
override fun enableNativeCSSParsing(): Boolean {
491501
var cached = enableNativeCSSParsingCache
492502
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<<2bf2a1dec031145181f6bc28c50cf32a>>
7+
* @generated SignedSource<<daf8cd270e8f69e6e0c410b4007ee28e>>
88
*/
99

1010
/**
@@ -112,6 +112,8 @@ public object ReactNativeFeatureFlagsCxxInterop {
112112

113113
@DoNotStrip @JvmStatic public external fun enableModuleArgumentNSNullConversionIOS(): Boolean
114114

115+
@DoNotStrip @JvmStatic public external fun enableMutationObserverByDefault(): Boolean
116+
115117
@DoNotStrip @JvmStatic public external fun enableNativeCSSParsing(): Boolean
116118

117119
@DoNotStrip @JvmStatic public external fun enableNativeViewPropTransformations(): 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<<89cd07b543fc079341bb3a5d90e50d13>>
7+
* @generated SignedSource<<0e10c51dcebd6077237c0c0aaff251e8>>
88
*/
99

1010
/**
@@ -107,6 +107,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
107107

108108
override fun enableModuleArgumentNSNullConversionIOS(): Boolean = false
109109

110+
override fun enableMutationObserverByDefault(): Boolean = false
111+
110112
override fun enableNativeCSSParsing(): Boolean = false
111113

112114
override fun enableNativeViewPropTransformations(): Boolean = false

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<<e82235d73386509fc2378a5b8e4b2cfa>>
7+
* @generated SignedSource<<b1d196c0623e11fbcf59b38143fbe37e>>
88
*/
99

1010
/**
@@ -66,6 +66,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
6666
private var enableLayoutAnimationsOnIOSCache: Boolean? = null
6767
private var enableMainQueueCoordinatorOnIOSCache: Boolean? = null
6868
private var enableModuleArgumentNSNullConversionIOSCache: Boolean? = null
69+
private var enableMutationObserverByDefaultCache: Boolean? = null
6970
private var enableNativeCSSParsingCache: Boolean? = null
7071
private var enableNativeViewPropTransformationsCache: Boolean? = null
7172
private var enableNetworkEventReportingCache: Boolean? = null
@@ -533,6 +534,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
533534
return cached
534535
}
535536

537+
override fun enableMutationObserverByDefault(): Boolean {
538+
var cached = enableMutationObserverByDefaultCache
539+
if (cached == null) {
540+
cached = currentProvider.enableMutationObserverByDefault()
541+
accessedFeatureFlags.add("enableMutationObserverByDefault")
542+
enableMutationObserverByDefaultCache = cached
543+
}
544+
return cached
545+
}
546+
536547
override fun enableNativeCSSParsing(): Boolean {
537548
var cached = enableNativeCSSParsingCache
538549
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<<e3051a7aec6e7da31a65eb2d58fcd64b>>
7+
* @generated SignedSource<<fd463e05fc06ba5bae4f1e0bb99e72b2>>
88
*/
99

1010
/**
@@ -107,6 +107,8 @@ public interface ReactNativeFeatureFlagsProvider {
107107

108108
@DoNotStrip public fun enableModuleArgumentNSNullConversionIOS(): Boolean
109109

110+
@DoNotStrip public fun enableMutationObserverByDefault(): Boolean
111+
110112
@DoNotStrip public fun enableNativeCSSParsing(): Boolean
111113

112114
@DoNotStrip public fun enableNativeViewPropTransformations(): Boolean

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ add_react_common_subdir(react/renderer/components/safeareaview)
118118
add_react_common_subdir(react/renderer/leakchecker)
119119
add_react_common_subdir(react/renderer/observers/events)
120120
add_react_common_subdir(react/renderer/observers/intersection)
121+
add_react_common_subdir(react/renderer/observers/mutation)
121122
add_react_common_subdir(react/renderer/textlayoutmanager)
122123
add_react_common_subdir(react/utils)
123124
add_react_common_subdir(react/bridging)
@@ -129,6 +130,7 @@ add_react_common_subdir(react/nativemodule/featureflags)
129130
add_react_common_subdir(react/nativemodule/microtasks)
130131
add_react_common_subdir(react/nativemodule/idlecallbacks)
131132
add_react_common_subdir(react/nativemodule/intersectionobserver)
133+
add_react_common_subdir(react/nativemodule/mutationobserver)
132134
add_react_common_subdir(react/nativemodule/webperformance)
133135
add_react_common_subdir(react/networking)
134136
add_react_common_subdir(jserrorhandler)
@@ -198,6 +200,7 @@ add_library(reactnative
198200
$<TARGET_OBJECTS:react_nativemodule_idlecallbacks>
199201
$<TARGET_OBJECTS:react_nativemodule_intersectionobserver>
200202
$<TARGET_OBJECTS:react_nativemodule_microtasks>
203+
$<TARGET_OBJECTS:react_nativemodule_mutationobserver>
201204
$<TARGET_OBJECTS:react_nativemodule_webperformance>
202205
$<TARGET_OBJECTS:react_networking>
203206
$<TARGET_OBJECTS:react_newarchdefaults>
@@ -220,6 +223,7 @@ add_library(reactnative
220223
$<TARGET_OBJECTS:react_renderer_mounting>
221224
$<TARGET_OBJECTS:react_renderer_observers_events>
222225
$<TARGET_OBJECTS:react_renderer_observers_intersection>
226+
$<TARGET_OBJECTS:react_renderer_observers_mutation>
223227
$<TARGET_OBJECTS:react_renderer_runtimescheduler>
224228
$<TARGET_OBJECTS:react_renderer_scheduler>
225229
$<TARGET_OBJECTS:react_renderer_telemetry>
@@ -294,6 +298,7 @@ target_include_directories(reactnative
294298
$<TARGET_PROPERTY:react_nativemodule_idlecallbacks,INTERFACE_INCLUDE_DIRECTORIES>
295299
$<TARGET_PROPERTY:react_nativemodule_intersectionobserver,INTERFACE_INCLUDE_DIRECTORIES>
296300
$<TARGET_PROPERTY:react_nativemodule_microtasks,INTERFACE_INCLUDE_DIRECTORIES>
301+
$<TARGET_PROPERTY:react_nativemodule_mutationobserver,INTERFACE_INCLUDE_DIRECTORIES>
297302
$<TARGET_PROPERTY:react_nativemodule_webperformance,INTERFACE_INCLUDE_DIRECTORIES>
298303
$<TARGET_PROPERTY:react_networking,INTERFACE_INCLUDE_DIRECTORIES>
299304
$<TARGET_PROPERTY:react_newarchdefaults,INTERFACE_INCLUDE_DIRECTORIES>
@@ -317,6 +322,8 @@ target_include_directories(reactnative
317322
$<TARGET_PROPERTY:react_renderer_mapbuffer,INTERFACE_INCLUDE_DIRECTORIES>
318323
$<TARGET_PROPERTY:react_renderer_mounting,INTERFACE_INCLUDE_DIRECTORIES>
319324
$<TARGET_PROPERTY:react_renderer_observers_events,INTERFACE_INCLUDE_DIRECTORIES>
325+
$<TARGET_PROPERTY:react_renderer_observers_intersection,INTERFACE_INCLUDE_DIRECTORIES>
326+
$<TARGET_PROPERTY:react_renderer_observers_mutation,INTERFACE_INCLUDE_DIRECTORIES>
320327
$<TARGET_PROPERTY:react_renderer_runtimescheduler,INTERFACE_INCLUDE_DIRECTORIES>
321328
$<TARGET_PROPERTY:react_renderer_scheduler,INTERFACE_INCLUDE_DIRECTORIES>
322329
$<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<<95380ca380ce7c5d3d2293b105d42247>>
7+
* @generated SignedSource<<e1d6bbba43ad263257ed723f3a6c2600>>
88
*/
99

1010
/**
@@ -291,6 +291,12 @@ class ReactNativeFeatureFlagsJavaProvider
291291
return method(javaProvider_);
292292
}
293293

294+
bool enableMutationObserverByDefault() override {
295+
static const auto method =
296+
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableMutationObserverByDefault");
297+
return method(javaProvider_);
298+
}
299+
294300
bool enableNativeCSSParsing() override {
295301
static const auto method =
296302
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableNativeCSSParsing");
@@ -781,6 +787,11 @@ bool JReactNativeFeatureFlagsCxxInterop::enableModuleArgumentNSNullConversionIOS
781787
return ReactNativeFeatureFlags::enableModuleArgumentNSNullConversionIOS();
782788
}
783789

790+
bool JReactNativeFeatureFlagsCxxInterop::enableMutationObserverByDefault(
791+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
792+
return ReactNativeFeatureFlags::enableMutationObserverByDefault();
793+
}
794+
784795
bool JReactNativeFeatureFlagsCxxInterop::enableNativeCSSParsing(
785796
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
786797
return ReactNativeFeatureFlags::enableNativeCSSParsing();
@@ -1168,6 +1179,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
11681179
makeNativeMethod(
11691180
"enableModuleArgumentNSNullConversionIOS",
11701181
JReactNativeFeatureFlagsCxxInterop::enableModuleArgumentNSNullConversionIOS),
1182+
makeNativeMethod(
1183+
"enableMutationObserverByDefault",
1184+
JReactNativeFeatureFlagsCxxInterop::enableMutationObserverByDefault),
11711185
makeNativeMethod(
11721186
"enableNativeCSSParsing",
11731187
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<<72294df9c57d40232a21ab83bcbd12cc>>
7+
* @generated SignedSource<<c3a280ebf9c5b95d484f3b79fb1ac3e5>>
88
*/
99

1010
/**
@@ -156,6 +156,9 @@ class JReactNativeFeatureFlagsCxxInterop
156156
static bool enableModuleArgumentNSNullConversionIOS(
157157
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
158158

159+
static bool enableMutationObserverByDefault(
160+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
161+
159162
static bool enableNativeCSSParsing(
160163
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
161164

0 commit comments

Comments
 (0)