Skip to content

Commit a337cee

Browse files
Copilotanupriya13
andcommitted
Fix deadlock in ReactInstanceWin::DetachRootView by replacing sync call with async
Co-authored-by: anupriya13 <54227869+anupriya13@users.noreply.github.com>
1 parent 0394704 commit a337cee

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,8 +1514,15 @@ void ReactInstanceWin::DetachRootView(facebook::react::IReactRootView *rootView,
15141514
CallJsFunction("AppRegistry", "unmountApplicationComponentAtRootTag", std::move(params));
15151515
}
15161516

1517-
// Give the JS thread time to finish executing
1518-
m_jsMessageThread.Load()->runOnQueueSync([]() {});
1517+
// Schedule an async task on the JS thread to ensure previous operations complete
1518+
// This avoids the deadlock that can occur with runOnQueueSync when the JS thread
1519+
// is busy with garbage collection or other operations
1520+
if (auto jsMessageThread = m_jsMessageThread.Load()) {
1521+
jsMessageThread->runOnQueue([]() {
1522+
// This async operation ensures that any previously queued JS operations
1523+
// (like the unmount call above) have a chance to complete
1524+
});
1525+
}
15191526
}
15201527

15211528
Mso::CntPtr<IReactInstanceInternal> MakeReactInstance(

0 commit comments

Comments
 (0)