From e2b661c8f62569c20658311a15f5a11cf735bdbe 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 9fd7644c0ba..29178668c21 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 4cfcac4d071..a41789fda41 100644 --- a/vnext/Microsoft.ReactNative/Fabric/FabricUIManagerModule.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/FabricUIManagerModule.cpp @@ -176,6 +176,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(