diff --git a/packages/e2e-test-app-fabric/windows/RNTesterApp-Fabric/RNTesterApp-Fabric.cpp b/packages/e2e-test-app-fabric/windows/RNTesterApp-Fabric/RNTesterApp-Fabric.cpp index 4b64dfe33cc..e13b20d9151 100644 --- a/packages/e2e-test-app-fabric/windows/RNTesterApp-Fabric/RNTesterApp-Fabric.cpp +++ b/packages/e2e-test-app-fabric/windows/RNTesterApp-Fabric/RNTesterApp-Fabric.cpp @@ -464,9 +464,14 @@ void DumpUIAPatternInfo(IUIAutomationElement *pTarget, const winrt::Windows::Dat winrt::com_ptr textRangePattern; hr = textPattern->get_DocumentRange(textRangePattern.put()); if (SUCCEEDED(hr) && textRangePattern) { - textRangePattern->GetText(20, &text); - if (SUCCEEDED(hr)) { - InsertStringValueIfNotEmpty(result, L"TextRangePattern.GetText", text); + // Clone the text range provider before accessing its methods to avoid hangs + winrt::com_ptr clonedTextRange; + hr = textRangePattern->Clone(clonedTextRange.put()); + if (SUCCEEDED(hr) && clonedTextRange) { + hr = clonedTextRange->GetText(20, &text); + if (SUCCEEDED(hr)) { + InsertStringValueIfNotEmpty(result, L"TextRangePattern.GetText", text); + } } } } diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionTextRangeProvider.cpp b/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionTextRangeProvider.cpp index 1f69c84b3df..c3967fa30f6 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionTextRangeProvider.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionTextRangeProvider.cpp @@ -18,8 +18,18 @@ CompositionTextRangeProvider::CompositionTextRangeProvider( } HRESULT __stdcall CompositionTextRangeProvider::Clone(ITextRangeProvider **pRetVal) { - // no-op - *pRetVal = nullptr; + if (pRetVal == nullptr) + return E_POINTER; + + auto strongView = m_view.view(); + if (!strongView) + return UIA_E_ELEMENTNOTAVAILABLE; + + // Create a new instance of CompositionTextRangeProvider with the same view and parent provider + auto clonedProvider = winrt::make( + strongView.as(), m_parentProvider.get()); + + *pRetVal = clonedProvider.detach(); return S_OK; }