From 492f96eb5fd09dbaf8191d13b0bc7ebdb030d63c Mon Sep 17 00:00:00 2001 From: Abhijeet Jha <74712637+iamAbhi-916@users.noreply.github.com> Date: Wed, 19 Nov 2025 11:44:26 +0530 Subject: [PATCH] Fix modal Crash after closing DesktopPopupSiteBridge (#15384) * visual studio 2026 strict check fix * Fix Crash after closing DesktopPopupSiteBridge * Change files * yarn lint:fix amd format * remove debug logs * Revert "visual studio 2026 strict check fix" * visual studio 2026 strict check fix * nit comment --- ...-5bdf4573-dfbe-41fd-9dc0-4c4a7119957e.json | 7 ++ .../WindowsModalHostViewComponentView.cpp | 74 ++++++++++--------- 2 files changed, 48 insertions(+), 33 deletions(-) create mode 100644 change/react-native-windows-5bdf4573-dfbe-41fd-9dc0-4c4a7119957e.json diff --git a/change/react-native-windows-5bdf4573-dfbe-41fd-9dc0-4c4a7119957e.json b/change/react-native-windows-5bdf4573-dfbe-41fd-9dc0-4c4a7119957e.json new file mode 100644 index 00000000000..d26de73abfc --- /dev/null +++ b/change/react-native-windows-5bdf4573-dfbe-41fd-9dc0-4c4a7119957e.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Fix Crash after closing DesktopPopupSiteBridge", + "packageName": "react-native-windows", + "email": "74712637+iamAbhi-916@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp b/vnext/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp index 99632acbcc9..968d070aeb6 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp @@ -35,26 +35,38 @@ struct ModalHostState struct ModalHostView : public winrt::implements, ::Microsoft::ReactNativeSpecs::BaseModalHostView { ~ModalHostView() { - if (m_reactNativeIsland) { - m_reactNativeIsland.Island().Close(); - } + if (m_popUp) { + // Unregister closing event handler + if (m_appWindow && m_appWindowClosingToken) { + m_appWindow.Closing(m_appWindowClosingToken); + m_appWindowClosingToken.value = 0; + } - // Add AppWindow closing token cleanup - if (m_appWindow && m_appWindowClosingToken) { - m_appWindow.Closing(m_appWindowClosingToken); - m_appWindowClosingToken.value = 0; - } + // Reset topWindowID before destroying + if (m_prevWindowID) { + winrt::Microsoft::ReactNative::ReactCoreInjection::SetTopLevelWindowId( + m_reactContext.Properties().Handle(), m_prevWindowID); + m_prevWindowID = 0; + } - if (m_popUp) { - if (m_departFocusToken && !m_popUp.IsClosed()) { - // WASDK BUG: InputFocusNavigationHost::GetForSiteBridge fails on a DesktopPopupSiteBridge - // https://github.com/microsoft/react-native-windows/issues/14604 - /* - auto navHost = - winrt::Microsoft::UI::Input::InputFocusNavigationHost::GetForSiteBridge(m_popUp.as()); - navHost.DepartFocusRequested(m_departFocusToken); - */ + // Close island + if (m_reactNativeIsland) { + m_reactNativeIsland.Island().Close(); + m_reactNativeIsland = nullptr; + } + + // Hide popup + if (m_popUp.IsVisible()) { + m_popUp.Hide(); + } + + // Destroy AppWindow this automatically resumes parent window to receive inputs + if (m_appWindow) { + m_appWindow.Destroy(); + m_appWindow = nullptr; } + + // Close bridge m_popUp.Close(); m_popUp = nullptr; } @@ -88,7 +100,7 @@ struct ModalHostView : public winrt::implementsonDismiss(eventArgs); } - - // reset the topWindowID - if (m_prevWindowID) { - winrt::Microsoft::ReactNative::ReactCoreInjection::SetTopLevelWindowId( - m_reactContext.Properties().Handle(), m_prevWindowID); - m_prevWindowID = 0; - } } // creates a new modal window