From 9f95c043453099d418cd456b91f68683ff2cd763 Mon Sep 17 00:00:00 2001 From: Abhijeet Jha <74712637+iamAbhi-916@users.noreply.github.com> Date: Tue, 28 Oct 2025 16:19:36 +0530 Subject: [PATCH 1/8] visual studio 2026 strict check fix --- .../Fabric/Composition/UiaHelpers.cpp | 12 ++++++++---- vnext/Mso/src/dispatchQueue/queueService.cpp | 4 +++- vnext/Mso/src/dispatchQueue/uiScheduler_winrt.cpp | 3 ++- vnext/Shared/Networking/OriginPolicyHttpFilter.cpp | 3 ++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.cpp b/vnext/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.cpp index 68551fd5f22..2de775887a3 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.cpp @@ -48,7 +48,8 @@ HRESULT UiaNavigateHelper( uint32_t index = children.Size() - 1; do { auto child = children.GetAt(index).as(); - if (uiaProvider = child->EnsureUiaProvider()) { + uiaProvider = child->EnsureUiaProvider(); + if (uiaProvider) { break; } } while (index-- != 0); @@ -60,7 +61,8 @@ HRESULT UiaNavigateHelper( uint32_t index = 0; do { auto child = children.GetAt(index).as(); - if (uiaProvider = child->EnsureUiaProvider()) { + uiaProvider = child->EnsureUiaProvider(); + if (uiaProvider) { break; } } while (++index != children.Size()); @@ -74,7 +76,8 @@ HRESULT UiaNavigateHelper( while (++it != children.end()) { auto nextchild = (*it).as(); - if (uiaProvider = nextchild->EnsureUiaProvider()) { + uiaProvider = nextchild->EnsureUiaProvider(); + if (uiaProvider) { break; } } @@ -91,7 +94,8 @@ HRESULT UiaNavigateHelper( do { it--; auto prevchild = (*it).as(); - if (uiaProvider = prevchild->EnsureUiaProvider()) { + uiaProvider = prevchild->EnsureUiaProvider(); + if (uiaProvider) { break; } } while (it != children.begin()); diff --git a/vnext/Mso/src/dispatchQueue/queueService.cpp b/vnext/Mso/src/dispatchQueue/queueService.cpp index d8e8c240173..1738951a2b3 100644 --- a/vnext/Mso/src/dispatchQueue/queueService.cpp +++ b/vnext/Mso/src/dispatchQueue/queueService.cpp @@ -205,8 +205,10 @@ void QueueService::InvokeTask( DispatchTask taskToInvoke{std::move(task)}; taskToInvoke.Get()->Invoke(); // Call Get()->Invoke instead of operator() to flatten call stack - while (taskToInvoke = context.TakeNextDeferredTask()) { + taskToInvoke = context.TakeNextDeferredTask(); + while (taskToInvoke) { taskToInvoke.Get()->Invoke(); + taskToInvoke = context.TakeNextDeferredTask(); } } diff --git a/vnext/Mso/src/dispatchQueue/uiScheduler_winrt.cpp b/vnext/Mso/src/dispatchQueue/uiScheduler_winrt.cpp index 5a469852d45..9cc091cdbc0 100644 --- a/vnext/Mso/src/dispatchQueue/uiScheduler_winrt.cpp +++ b/vnext/Mso/src/dispatchQueue/uiScheduler_winrt.cpp @@ -271,7 +271,8 @@ bool UISchedulerWinRT::TryTakeTask( --m_taskCount; } - if (queue = m_queue.GetStrongPtr()) { + queue = m_queue.GetStrongPtr(); + if (queue) { return queue->TryDequeTask(task); } diff --git a/vnext/Shared/Networking/OriginPolicyHttpFilter.cpp b/vnext/Shared/Networking/OriginPolicyHttpFilter.cpp index 1179be69311..4ae3c1a47be 100644 --- a/vnext/Shared/Networking/OriginPolicyHttpFilter.cpp +++ b/vnext/Shared/Networking/OriginPolicyHttpFilter.cpp @@ -758,7 +758,8 @@ ResponseOperation OriginPolicyHttpFilter::SendRequestAsync(HttpRequestMessage co if (originPolicy == OriginPolicy::CrossOriginResourceSharing) { // If inner filter can AllowRedirect, disable for preflight. winrt::impl::com_ref baseFilter; - if (baseFilter = m_innerFilter.try_as()) { + baseFilter = m_innerFilter.try_as(); + if (baseFilter) { baseFilter.AllowAutoRedirect(false); } From 40f99a81890f9998f0c4b042af3bce4c2b3205a7 Mon Sep 17 00:00:00 2001 From: Abhijeet Jha <74712637+iamAbhi-916@users.noreply.github.com> Date: Tue, 18 Nov 2025 16:54:04 +0530 Subject: [PATCH 2/8] Fix Crash after closing DesktopPopupSiteBridge --- .../WindowsModalHostViewComponentView.cpp | 78 +++++++++++-------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp b/vnext/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp index 99632acbcc9..2ce1fa66548 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp @@ -35,26 +35,39 @@ struct ModalHostState struct ModalHostView : public winrt::implements, ::Microsoft::ReactNativeSpecs::BaseModalHostView { ~ModalHostView() { - if (m_reactNativeIsland) { - m_reactNativeIsland.Island().Close(); - } + OutputDebugStringW(L"→ destructor() called\n"); + if (m_popUp) { + // Unregister closing event handler (when to handle event token ) + 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 +101,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 From 8a7df11b35e736ddfaf2ee1f291b85e341dc7fc1 Mon Sep 17 00:00:00 2001 From: Abhijeet Jha <74712637+iamAbhi-916@users.noreply.github.com> Date: Tue, 18 Nov 2025 16:56:04 +0530 Subject: [PATCH 3/8] Change files --- ...ative-windows-5bdf4573-dfbe-41fd-9dc0-4c4a7119957e.json | 7 +++++++ 1 file changed, 7 insertions(+) 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" +} From ff5243df355e053dcee07a96041a79b96db402c1 Mon Sep 17 00:00:00 2001 From: Abhijeet Jha <74712637+iamAbhi-916@users.noreply.github.com> Date: Tue, 18 Nov 2025 17:11:27 +0530 Subject: [PATCH 4/8] yarn lint:fix amd format --- .../Composition/Modal/WindowsModalHostViewComponentView.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp b/vnext/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp index 2ce1fa66548..012a879f594 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp @@ -232,7 +232,7 @@ struct ModalHostView : public winrt::implements Date: Tue, 28 Oct 2025 16:19:36 +0530 Subject: [PATCH 5/8] remove debug logs --- .../Composition/Modal/WindowsModalHostViewComponentView.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp b/vnext/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp index 012a879f594..4c8fe637ea7 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp @@ -35,7 +35,6 @@ struct ModalHostState struct ModalHostView : public winrt::implements, ::Microsoft::ReactNativeSpecs::BaseModalHostView { ~ModalHostView() { - OutputDebugStringW(L"→ destructor() called\n"); if (m_popUp) { // Unregister closing event handler (when to handle event token ) if (m_appWindow && m_appWindowClosingToken) { @@ -237,7 +236,6 @@ struct ModalHostView : public winrt::implements Date: Tue, 18 Nov 2025 17:28:37 +0530 Subject: [PATCH 6/8] Revert "visual studio 2026 strict check fix" --- .../Fabric/Composition/UiaHelpers.cpp | 12 ++++-------- vnext/Mso/src/dispatchQueue/queueService.cpp | 4 +--- vnext/Mso/src/dispatchQueue/uiScheduler_winrt.cpp | 3 +-- vnext/Shared/Networking/OriginPolicyHttpFilter.cpp | 3 +-- 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.cpp b/vnext/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.cpp index 2de775887a3..68551fd5f22 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.cpp @@ -48,8 +48,7 @@ HRESULT UiaNavigateHelper( uint32_t index = children.Size() - 1; do { auto child = children.GetAt(index).as(); - uiaProvider = child->EnsureUiaProvider(); - if (uiaProvider) { + if (uiaProvider = child->EnsureUiaProvider()) { break; } } while (index-- != 0); @@ -61,8 +60,7 @@ HRESULT UiaNavigateHelper( uint32_t index = 0; do { auto child = children.GetAt(index).as(); - uiaProvider = child->EnsureUiaProvider(); - if (uiaProvider) { + if (uiaProvider = child->EnsureUiaProvider()) { break; } } while (++index != children.Size()); @@ -76,8 +74,7 @@ HRESULT UiaNavigateHelper( while (++it != children.end()) { auto nextchild = (*it).as(); - uiaProvider = nextchild->EnsureUiaProvider(); - if (uiaProvider) { + if (uiaProvider = nextchild->EnsureUiaProvider()) { break; } } @@ -94,8 +91,7 @@ HRESULT UiaNavigateHelper( do { it--; auto prevchild = (*it).as(); - uiaProvider = prevchild->EnsureUiaProvider(); - if (uiaProvider) { + if (uiaProvider = prevchild->EnsureUiaProvider()) { break; } } while (it != children.begin()); diff --git a/vnext/Mso/src/dispatchQueue/queueService.cpp b/vnext/Mso/src/dispatchQueue/queueService.cpp index 1738951a2b3..d8e8c240173 100644 --- a/vnext/Mso/src/dispatchQueue/queueService.cpp +++ b/vnext/Mso/src/dispatchQueue/queueService.cpp @@ -205,10 +205,8 @@ void QueueService::InvokeTask( DispatchTask taskToInvoke{std::move(task)}; taskToInvoke.Get()->Invoke(); // Call Get()->Invoke instead of operator() to flatten call stack - taskToInvoke = context.TakeNextDeferredTask(); - while (taskToInvoke) { + while (taskToInvoke = context.TakeNextDeferredTask()) { taskToInvoke.Get()->Invoke(); - taskToInvoke = context.TakeNextDeferredTask(); } } diff --git a/vnext/Mso/src/dispatchQueue/uiScheduler_winrt.cpp b/vnext/Mso/src/dispatchQueue/uiScheduler_winrt.cpp index 9cc091cdbc0..5a469852d45 100644 --- a/vnext/Mso/src/dispatchQueue/uiScheduler_winrt.cpp +++ b/vnext/Mso/src/dispatchQueue/uiScheduler_winrt.cpp @@ -271,8 +271,7 @@ bool UISchedulerWinRT::TryTakeTask( --m_taskCount; } - queue = m_queue.GetStrongPtr(); - if (queue) { + if (queue = m_queue.GetStrongPtr()) { return queue->TryDequeTask(task); } diff --git a/vnext/Shared/Networking/OriginPolicyHttpFilter.cpp b/vnext/Shared/Networking/OriginPolicyHttpFilter.cpp index 4ae3c1a47be..1179be69311 100644 --- a/vnext/Shared/Networking/OriginPolicyHttpFilter.cpp +++ b/vnext/Shared/Networking/OriginPolicyHttpFilter.cpp @@ -758,8 +758,7 @@ ResponseOperation OriginPolicyHttpFilter::SendRequestAsync(HttpRequestMessage co if (originPolicy == OriginPolicy::CrossOriginResourceSharing) { // If inner filter can AllowRedirect, disable for preflight. winrt::impl::com_ref baseFilter; - baseFilter = m_innerFilter.try_as(); - if (baseFilter) { + if (baseFilter = m_innerFilter.try_as()) { baseFilter.AllowAutoRedirect(false); } From e3901c0b89ee8f714672695368705e8c7f45b86b Mon Sep 17 00:00:00 2001 From: Abhijeet Jha <74712637+iamAbhi-916@users.noreply.github.com> Date: Tue, 28 Oct 2025 16:19:36 +0530 Subject: [PATCH 7/8] visual studio 2026 strict check fix --- .../Fabric/Composition/UiaHelpers.cpp | 12 ++++++++---- vnext/Mso/src/dispatchQueue/queueService.cpp | 4 +++- vnext/Mso/src/dispatchQueue/uiScheduler_winrt.cpp | 3 ++- vnext/Shared/Networking/OriginPolicyHttpFilter.cpp | 3 ++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.cpp b/vnext/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.cpp index 68551fd5f22..2de775887a3 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.cpp @@ -48,7 +48,8 @@ HRESULT UiaNavigateHelper( uint32_t index = children.Size() - 1; do { auto child = children.GetAt(index).as(); - if (uiaProvider = child->EnsureUiaProvider()) { + uiaProvider = child->EnsureUiaProvider(); + if (uiaProvider) { break; } } while (index-- != 0); @@ -60,7 +61,8 @@ HRESULT UiaNavigateHelper( uint32_t index = 0; do { auto child = children.GetAt(index).as(); - if (uiaProvider = child->EnsureUiaProvider()) { + uiaProvider = child->EnsureUiaProvider(); + if (uiaProvider) { break; } } while (++index != children.Size()); @@ -74,7 +76,8 @@ HRESULT UiaNavigateHelper( while (++it != children.end()) { auto nextchild = (*it).as(); - if (uiaProvider = nextchild->EnsureUiaProvider()) { + uiaProvider = nextchild->EnsureUiaProvider(); + if (uiaProvider) { break; } } @@ -91,7 +94,8 @@ HRESULT UiaNavigateHelper( do { it--; auto prevchild = (*it).as(); - if (uiaProvider = prevchild->EnsureUiaProvider()) { + uiaProvider = prevchild->EnsureUiaProvider(); + if (uiaProvider) { break; } } while (it != children.begin()); diff --git a/vnext/Mso/src/dispatchQueue/queueService.cpp b/vnext/Mso/src/dispatchQueue/queueService.cpp index d8e8c240173..1738951a2b3 100644 --- a/vnext/Mso/src/dispatchQueue/queueService.cpp +++ b/vnext/Mso/src/dispatchQueue/queueService.cpp @@ -205,8 +205,10 @@ void QueueService::InvokeTask( DispatchTask taskToInvoke{std::move(task)}; taskToInvoke.Get()->Invoke(); // Call Get()->Invoke instead of operator() to flatten call stack - while (taskToInvoke = context.TakeNextDeferredTask()) { + taskToInvoke = context.TakeNextDeferredTask(); + while (taskToInvoke) { taskToInvoke.Get()->Invoke(); + taskToInvoke = context.TakeNextDeferredTask(); } } diff --git a/vnext/Mso/src/dispatchQueue/uiScheduler_winrt.cpp b/vnext/Mso/src/dispatchQueue/uiScheduler_winrt.cpp index 5a469852d45..9cc091cdbc0 100644 --- a/vnext/Mso/src/dispatchQueue/uiScheduler_winrt.cpp +++ b/vnext/Mso/src/dispatchQueue/uiScheduler_winrt.cpp @@ -271,7 +271,8 @@ bool UISchedulerWinRT::TryTakeTask( --m_taskCount; } - if (queue = m_queue.GetStrongPtr()) { + queue = m_queue.GetStrongPtr(); + if (queue) { return queue->TryDequeTask(task); } diff --git a/vnext/Shared/Networking/OriginPolicyHttpFilter.cpp b/vnext/Shared/Networking/OriginPolicyHttpFilter.cpp index 1179be69311..4ae3c1a47be 100644 --- a/vnext/Shared/Networking/OriginPolicyHttpFilter.cpp +++ b/vnext/Shared/Networking/OriginPolicyHttpFilter.cpp @@ -758,7 +758,8 @@ ResponseOperation OriginPolicyHttpFilter::SendRequestAsync(HttpRequestMessage co if (originPolicy == OriginPolicy::CrossOriginResourceSharing) { // If inner filter can AllowRedirect, disable for preflight. winrt::impl::com_ref baseFilter; - if (baseFilter = m_innerFilter.try_as()) { + baseFilter = m_innerFilter.try_as(); + if (baseFilter) { baseFilter.AllowAutoRedirect(false); } From 289d27c2fdc7dd3e24c13504454cb983d1e00c32 Mon Sep 17 00:00:00 2001 From: Abhijeet Jha <74712637+iamAbhi-916@users.noreply.github.com> Date: Tue, 18 Nov 2025 21:05:06 +0530 Subject: [PATCH 8/8] nit comment --- .../Composition/Modal/WindowsModalHostViewComponentView.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp b/vnext/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp index 4c8fe637ea7..968d070aeb6 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp @@ -36,7 +36,7 @@ struct ModalHostView : public winrt::implements { ~ModalHostView() { if (m_popUp) { - // Unregister closing event handler (when to handle event token ) + // Unregister closing event handler if (m_appWindow && m_appWindowClosingToken) { m_appWindow.Closing(m_appWindowClosingToken); m_appWindowClosingToken.value = 0;