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 d01e812cd5d..c237aa762c3 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(