Skip to content

[Web] Do not set role on non HTMLElement nodes - #4159

Merged
m-bert merged 1 commit into
mainfrom
@mbert/native-role-crashes
May 8, 2026
Merged

[Web] Do not set role on non HTMLElement nodes#4159
m-bert merged 1 commit into
mainfrom
@mbert/native-role-crashes

Conversation

@m-bert

@m-bert m-bert commented May 8, 2026

Copy link
Copy Markdown
Collaborator

Description

In Gesture Handler 3 it is possible to attach GestureDetector not only to Views, but also to Text. However, this crashes on removeAttribute method.

Test plan

Nested text example

Copilot AI review requested due to automatic review settings May 8, 2026 10:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a web crash when API v3 GestureDetector is attached to non-View React Native components (e.g. Text) by ensuring the web-only native-gesture role attribute is only applied to actual HTMLElement nodes.

Changes:

  • Stop casting firstChild to HTMLElement and instead read it as-is.
  • Guard role attribute set/remove logic with child instanceof HTMLElement to avoid calling removeAttribute on non-elements (e.g. text nodes).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@m-bert
m-bert merged commit ab5ab7f into main May 8, 2026
7 checks passed
@m-bert
m-bert deleted the @mbert/native-role-crashes branch May 8, 2026 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants