From 10f9674e959fbb16b79cf2fe1773e12a3b4743b6 Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Fri, 11 Oct 2024 11:26:32 -0700 Subject: [PATCH] Fix RootComponentView leak (#13959) * Fix RootComponentView leak * Change files * format --------- Co-authored-by: React-Native-Windows Bot <53619745+rnbot@users.noreply.github.com> --- ...ative-windows-408fe985-f784-4dff-aed3-9045a0c7a420.json | 7 +++++++ .../Fabric/Composition/ReactNativeIsland.cpp | 1 + .../Microsoft.ReactNative/Fabric/FabricUIManagerModule.cpp | 3 +++ 3 files changed, 11 insertions(+) create mode 100644 change/react-native-windows-408fe985-f784-4dff-aed3-9045a0c7a420.json diff --git a/change/react-native-windows-408fe985-f784-4dff-aed3-9045a0c7a420.json b/change/react-native-windows-408fe985-f784-4dff-aed3-9045a0c7a420.json new file mode 100644 index 00000000000..a4b38758eac --- /dev/null +++ b/change/react-native-windows-408fe985-f784-4dff-aed3-9045a0c7a420.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Fix RootComponentView leak", + "packageName": "react-native-windows", + "email": "53619745+rnbot@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp b/vnext/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp index b9518d7a118..96bdb1b91c6 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp @@ -157,6 +157,7 @@ void ReactNativeIsland::ReactViewHost(winrt::Microsoft::ReactNative::IReactViewH } if (m_reactViewHost) { + UninitRootView(); m_reactViewHost.DetachViewInstance(); } diff --git a/vnext/Microsoft.ReactNative/Fabric/FabricUIManagerModule.cpp b/vnext/Microsoft.ReactNative/Fabric/FabricUIManagerModule.cpp index 9d4e999e232..64f8a0cc4b0 100644 --- a/vnext/Microsoft.ReactNative/Fabric/FabricUIManagerModule.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/FabricUIManagerModule.cpp @@ -155,6 +155,9 @@ void FabricUIManager::startSurface( void FabricUIManager::stopSurface(facebook::react::SurfaceId surfaceId) noexcept { m_surfaceManager->stopSurface(surfaceId); + auto &rootDescriptor = m_registry.componentViewDescriptorWithTag(surfaceId); + m_registry.enqueueComponentViewWithComponentHandle( + facebook::react::RootShadowNode::Handle(), surfaceId, rootDescriptor); } winrt::Microsoft::ReactNative::ReactNativeIsland FabricUIManager::GetReactNativeIsland(