Skip to content

Commit 7401fe8

Browse files
Copilotanupriya13
andcommitted
Move EnableSyncDetachRootView quirk option from React.h to public QuirkSettings API
Co-authored-by: anupriya13 <54227869+anupriya13@users.noreply.github.com>
1 parent 4642723 commit 7401fe8

6 files changed

Lines changed: 47 additions & 7 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Move EnableSyncDetachRootView quirk option from React.h to public QuirkSettings API",
4+
"packageName": "@rnw-dependencies",
5+
"email": "noreply@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

vnext/Microsoft.ReactNative/QuirkSettings.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ winrt::Microsoft::ReactNative::ReactPropertyId<bool> MapWindowDeactivatedToAppSt
6464
properties.Set(MapWindowDeactivatedToAppStateInactiveProperty(), value);
6565
}
6666

67+
/*static*/ void QuirkSettings::SetEnableSyncDetachRootView(
68+
winrt::Microsoft::ReactNative::ReactPropertyBag properties,
69+
bool value) noexcept {
70+
properties.Set(EnableSyncDetachRootViewProperty(), value);
71+
}
72+
6773
winrt::Microsoft::ReactNative::ReactPropertyId<bool> SuppressWindowFocusOnViewFocusProperty() noexcept {
6874
winrt::Microsoft::ReactNative::ReactPropertyId<bool> propId{
6975
L"ReactNative.QuirkSettings", L"SuppressWindowFocusOnViewFocus"};
@@ -77,6 +83,12 @@ winrt::Microsoft::ReactNative::ReactPropertyId<bool> UseRuntimeSchedulerProperty
7783
return propId;
7884
}
7985

86+
winrt::Microsoft::ReactNative::ReactPropertyId<bool> EnableSyncDetachRootViewProperty() noexcept {
87+
static winrt::Microsoft::ReactNative::ReactPropertyId<bool> propId{
88+
L"ReactNative.QuirkSettings", L"EnableSyncDetachRootView"};
89+
return propId;
90+
}
91+
8092
#pragma region IDL interface
8193

8294
/*static*/ void QuirkSettings::SetMatchAndroidAndIOSStretchBehavior(
@@ -121,6 +133,12 @@ winrt::Microsoft::ReactNative::ReactPropertyId<bool> UseRuntimeSchedulerProperty
121133
ReactPropertyBag(settings.Properties()).Set(UseRuntimeSchedulerProperty(), value);
122134
}
123135

136+
/*static*/ void QuirkSettings::SetEnableSyncDetachRootView(
137+
winrt::Microsoft::ReactNative::ReactInstanceSettings settings,
138+
bool value) noexcept {
139+
ReactPropertyBag(settings.Properties()).Set(EnableSyncDetachRootViewProperty(), value);
140+
}
141+
124142
#pragma endregion IDL interface
125143

126144
/*static*/ bool QuirkSettings::GetMatchAndroidAndIOSStretchBehavior(ReactPropertyBag properties) noexcept {
@@ -153,4 +171,8 @@ winrt::Microsoft::ReactNative::ReactPropertyId<bool> UseRuntimeSchedulerProperty
153171
return properties.Get(UseRuntimeSchedulerProperty()).value_or(true);
154172
}
155173

174+
/*static*/ bool QuirkSettings::GetEnableSyncDetachRootView(ReactPropertyBag properties) noexcept {
175+
return properties.Get(EnableSyncDetachRootViewProperty()).value_or(false);
176+
}
177+
156178
} // namespace winrt::Microsoft::ReactNative::implementation

vnext/Microsoft.ReactNative/QuirkSettings.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ struct QuirkSettings : QuirkSettingsT<QuirkSettings> {
3939
static bool GetMapWindowDeactivatedToAppStateInactive(
4040
winrt::Microsoft::ReactNative::ReactPropertyBag properties) noexcept;
4141

42+
static void SetEnableSyncDetachRootView(
43+
winrt::Microsoft::ReactNative::ReactPropertyBag properties,
44+
bool value) noexcept;
45+
static bool GetEnableSyncDetachRootView(winrt::Microsoft::ReactNative::ReactPropertyBag properties) noexcept;
46+
4247
#pragma region Public API - part of IDL interface
4348
static void SetMatchAndroidAndIOSStretchBehavior(
4449
winrt::Microsoft::ReactNative::ReactInstanceSettings settings,
@@ -65,6 +70,10 @@ struct QuirkSettings : QuirkSettingsT<QuirkSettings> {
6570
winrt::Microsoft::ReactNative::ReactInstanceSettings settings,
6671
bool value) noexcept;
6772

73+
static void SetEnableSyncDetachRootView(
74+
winrt::Microsoft::ReactNative::ReactInstanceSettings settings,
75+
bool value) noexcept;
76+
6877
#pragma endregion Public API - part of IDL interface
6978
};
7079

vnext/Microsoft.ReactNative/QuirkSettings.idl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ namespace Microsoft.ReactNative
6464
"By default `react-native-windows` will use the new RuntimeScheduler."
6565
"Setting this to false will revert the behavior to previous scheduling logic.")
6666
static void SetUseRuntimeScheduler(ReactInstanceSettings settings, Boolean value);
67+
68+
DOC_STRING(
69+
"QUIRK: Enable synchronous wait in DetachRootView for JS thread completion. "
70+
"This flag re-enables the legacy runOnQueueSync call that can cause deadlocks "
71+
"with Hermes GC. Only enable if removal of sync behavior breaks your application.")
72+
DOC_DEFAULT("false")
73+
static void SetEnableSyncDetachRootView(ReactInstanceSettings settings, Boolean value);
6774
}
6875

6976
} // namespace Microsoft.ReactNative

vnext/Microsoft.ReactNative/ReactHost/React.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,6 @@ struct ReactOptions {
251251
//! It is not safe to expose to Custom Function. Add this flag so we can turn it off for Custom Function.
252252
bool EnableNativePerformanceNow{true};
253253

254-
//! QUIRK: Enable synchronous wait in DetachRootView for JS thread completion.
255-
//! This flag re-enables the legacy runOnQueueSync call that can cause deadlocks
256-
//! with Hermes GC. Only enable if removal of sync behavior breaks your application.
257-
//! Default: false (sync call is disabled to prevent deadlocks)
258-
bool EnableSyncDetachRootView{false};
259-
260254
ReactDevOptions DeveloperSettings = {};
261255

262256
//! This controls the availability of various developer support functionality including

vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,8 @@ void ReactInstanceWin::DetachRootView(facebook::react::IReactRootView *rootView,
15161516

15171517
// QUIRK: Legacy sync behavior can be re-enabled via EnableSyncDetachRootView option
15181518
// The sync call was removed to prevent deadlocks with Hermes GC operations
1519-
if (m_options.EnableSyncDetachRootView) {
1519+
auto propBag = ReactPropertyBag(m_reactContext->Properties());
1520+
if (QuirkSettings::GetEnableSyncDetachRootView(propBag)) {
15201521
// Legacy behavior: wait for JS thread to finish executing (can cause deadlocks)
15211522
m_jsMessageThread.Load()->runOnQueueSync([]() {});
15221523
}

0 commit comments

Comments
 (0)