Skip to content

Commit b99ccd7

Browse files
authored
[Fabric] Fix hang on shutdown when JS instance failed to start (#12867)
* Fix hang on shutdown when JS instance failed to start * Change files * dont wrap the ManualResetEvent in another shared_ptr * use unique_ptr since there is only one ref * fix
1 parent f83c158 commit b99ccd7

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "[Fabric] Fix hang on shutdown when JS instance failed to start",
4+
"packageName": "react-native-windows",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

vnext/Microsoft.ReactNative/Fabric/Composition/CompositionRootView.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,13 @@ void CompositionRootView::UpdateRootViewInternal() noexcept {
395395
}
396396
}
397397

398+
struct AutoMRE {
399+
~AutoMRE() {
400+
mre.Set();
401+
}
402+
Mso::ManualResetEvent mre;
403+
};
404+
398405
void CompositionRootView::UninitRootView() noexcept {
399406
if (!m_isInitialized) {
400407
return;
@@ -411,8 +418,10 @@ void CompositionRootView::UninitRootView() noexcept {
411418
// This is needed to ensure that the unmount JS logic is completed before the the instance is shutdown during
412419
// instance destruction. Aligns with similar code in ReactInstanceWin::DetachRootView for paper Future: Instead this
413420
// method should return a Promise, which should be resolved when the JS logic is complete.
421+
// The task will auto set the event on destruction to ensure that the event is set if the JS Queue has already been
422+
// shutdown
414423
Mso::ManualResetEvent mre;
415-
m_context.JSDispatcher().Post([&]() { mre.Set(); });
424+
m_context.JSDispatcher().Post([autoMRE = std::make_unique<AutoMRE>(AutoMRE{mre})]() {});
416425
mre.Wait();
417426

418427
// Paper version gives the JS thread time to finish executing - Is this needed?

0 commit comments

Comments
 (0)