fix(mobile): read React Native's role="link" as a link on Android

Merged
EM
3d ago
+128-5

What

On Android, a node React Native describes as a Link (role="link", which expo-router's Link sets) is now a link, as on iOS, so getByRole('link', name) finds it.

Why

React Native has no Android class for a link, so it sets the role description to Link on a plain View. The projection only knew the descriptions React Native spells into iOS values, and a link isn't one of them, so the node stayed a group.

How it works

  1. describedRole maps a Link description to link (packages/mobile/src/nodes.ts:408), case-insensitively like the other descriptions.
  2. Before React Native 0.84 a Text link also holds a Button for its link span, described as Link under the same name, and that's where a tap lands. echoedLinks (nodes.ts:428) finds a node described as Link whose direct Button child is described as Link under the node's text, and that parent keeps its class role, so the name matches once and the match is tappable. Without it, the outer link matches too, and agent-device refuses to tap it.
  3. A link inside plain text gets the same kind of Button, which was a button and is now a link.
  4. React Native sets a disabled Text link's state on the Text alone, so the span that echoes it takes that state (nodes.ts:695) and getByRole('link', { disabled: true }) finds it.

Issue

Fixes #2240

Verified

Ran it locally: yes

  • Android 13 x86_64 (redroid), the repro from the issue (Expo SDK 57, RN 0.86.3) and an expo-router app on RN 0.83 (a <Link asChild> header button and a <Link asChild><Text>), e2e run with each test calling getByRole('link', name).tap():
mainthis PR
repro, Pressable and Text linksgroup, LOCATOR_NOT_FOUND x2link, 2 passed
RN 0.83, <Link asChild> Pressablegroup, LOCATOR_NOT_FOUNDlink, passed
RN 0.83, <Link asChild><Text>group + button, LOCATOR_NOT_FOUNDgroup + link, passed
  • New case in nodes.test.ts; on main it fails with group Add note, button Go to home screen, button terms. It also covers a link card with a same-named link two levels down or directly inside it as a View, where both stay links. Dropping the Button check, the name comparison or the unnamed guard each fails it.
  • A real phone too, a Tecno Spark 20 (Android 13, arm64): the same results, plus a disabled pre-0.84 Text link as group [disabled] + link [disabled] (table).
  • @e2e-dev/mobile unit tests 650/650, tsc --noEmit and oxlint clean.
  • Not run on iOS. iOS output doesn't change: an iOS Link element already maps to link.

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.
  • Breaking change: title carries !, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md).
  • Docs updated in the same PR: the docs/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.