fix(mobile): read React Native's role="link" as a link on Android
Merged
EM
3d ago+128+128+012345678901234567890123456789-5-5-0123456789
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
describedRolemaps aLinkdescription tolink(packages/mobile/src/nodes.ts:408), case-insensitively like the other descriptions.- Before React Native 0.84 a
Textlink also holds aButtonfor its link span, described asLinkunder the same name, and that's where a tap lands.echoedLinks(nodes.ts:428) finds a node described asLinkwhose directButtonchild is described asLinkunder 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. - A link inside plain text gets the same kind of
Button, which was abuttonand is now alink. - React Native sets a disabled
Textlink's state on theTextalone, so the span that echoes it takes that state (nodes.ts:695) andgetByRole('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 runwith each test callinggetByRole('link', name).tap():
| main | this PR | |
|---|---|---|
repro, Pressable and Text links | group, LOCATOR_NOT_FOUND x2 | link, 2 passed |
RN 0.83, <Link asChild> Pressable | group, LOCATOR_NOT_FOUND | link, passed |
RN 0.83, <Link asChild><Text> | group + button, LOCATOR_NOT_FOUND | group + link, passed |
- New case in
nodes.test.ts; on main it fails withgroup 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 aView, where both stay links. Dropping theButtoncheck, 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
Textlink asgroup [disabled]+link [disabled](table). @e2e-dev/mobileunit tests 650/650,tsc --noEmitand oxlint clean.- Not run on iOS. iOS output doesn't change: an iOS
Linkelement already maps tolink.
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/**/*.mdxpage for the behavior, andskills/e2e/if the skill describes it. - Contract change: emitted
.d.tsreviewed,tests/types/sdk-types.tsupdated; wire change edits the schema and both fixtures. - Engine contract change (
e2e/engine): changesets fore2e,@e2e-dev/web, and@e2e-dev/mobile.