diff --git a/change/react-native-windows-0ddd05a5-b75b-423a-a461-6dcafc41d3b4.json b/change/react-native-windows-0ddd05a5-b75b-423a-a461-6dcafc41d3b4.json new file mode 100644 index 00000000000..68ff55561cc --- /dev/null +++ b/change/react-native-windows-0ddd05a5-b75b-423a-a461-6dcafc41d3b4.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "fix: null dereference in get_SelectionContainer when no container found", + "packageName": "react-native-windows", + "email": "66076509+vineethkuttan@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.cpp b/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.cpp index 30fbc50895b..a1d7ba41d2f 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.cpp @@ -1064,6 +1064,11 @@ HRESULT __stdcall CompositionDynamicAutomationProvider::get_SelectionContainer(I *pRetVal = nullptr; auto selectionContainerView = GetSelectionContainer(); + // Per UIA spec, returning S_OK with *pRetVal == nullptr is correct when the element + // is not contained within a selection container. + if (!selectionContainerView) + return S_OK; + auto uiaProvider = winrt::get_self(selectionContainerView) ->EnsureUiaProvider();