SIGN IN SIGN UP
facebook / react-native UNCLAIMED

A framework for building native applications using React

0 0 0 C++

Only generate recursive accessibility label for accessible elements (#51988)

Summary:
When trying to implement e2e tests using maestro in a large app I ran into major performance issues. I tracked it down to the generation of recursive accessibility labels.

The maestro iOS driver uses [XCUIElement snapshot dictionaryRepresentation](https://developer.apple.com/documentation/xctest/xcuielementsnapshot/dictionaryrepresentation) [here](https://github.com/mobile-dev-inc/Maestro/blob/96e8c9a2be3430be991c13d033486d52d2001334/maestro-ios-xctest-runner/maestro-driver-iosUITests/Routes/Handlers/ViewHierarchyHandler.swift#L234) to get a representation of the view hierarchy. The problem is that will query the accessibilityLabel for every single view, starting from the root of the app. It goes without saying that this is extremely slow since it traverses the view hierarchy, executing a recursive function on each one.

I think the only way to fix this is to avoid generating these recursive labels when not needed. From my understanding these should only be needed for accessible views.

## Changelog:

[IOS] [CHANGED] - Only generate recursive accessibility label for accessible elements

Pull Request resolved: https://github.com/facebook/react-native/pull/51988

Test Plan:
- Tested using VoiceOver in RN tester to make sure it works exactly the same.
- Tested in an app using Maestro to make sure this fixes the performance issue.
- Tested in RNTester running Maestro e2e test by creating a larger view hierarchy to make the problem more apparent, and simulate a real app. Using [this code](https://gist.github.com/janicduplessis/9f6b302d92b4e22ff5e8462a8a84e237) in RNTesterAppShared.js

Before:

```
❯ yarn e2e-test-ios
yarn run v1.22.22
$ ./scripts/maestro-test-ios.sh

Waiting for flows to complete...
[Passed] flatlist (14s)
[Passed] text (28s)
[Passed] modal (16s)
[Passed] image (8s)
[Passed] button (10s)
[Passed] legacy-native-module (32s)
[Passed] pressable (32s)
[Passed] new-arch-examples (35s)

8/8 Flows Passed in 2m 55s

✨  Done in 180.26s.
```

After:

```
❯ yarn e2e-test-ios
yarn run v1.22.22
$ ./scripts/maestro-test-ios.sh

Waiting for flows to complete...
[Passed] flatlist (7s)
[Passed] text (15s)
[Passed] modal (10s)
[Passed] image (4s)
[Passed] button (6s)
[Passed] legacy-native-module (16s)
[Passed] pressable (16s)
[Passed] new-arch-examples (17s)

8/8 Flows Passed in 1m 31s

✨  Done in 97.53s.
```

Reviewed By: christophpurrer, joevilches

Differential Revision: D76581949

Pulled By: cipolleschi

fbshipit-source-id: 0689c7d43a0c865572c4ee5ea32ee9b2dcb33ad5
J
Janic Duplessis committed
7e2f17ffe229e09288deba9061221835300ec153
Parent: e13ee7a
Committed by Facebook GitHub Bot <facebook-github-bot@users.noreply.github.com> on 6/16/2025, 5:30:33 PM