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(