Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: onPointerDown not called when rendered in 'display: contents' root #29890

Open
V3RON opened this issue Jun 13, 2024 · 3 comments
Open

Bug: onPointerDown not called when rendered in 'display: contents' root #29890

V3RON opened this issue Jun 13, 2024 · 3 comments

Comments

@V3RON
Copy link

V3RON commented Jun 13, 2024

onPointerDown listeners are not called in iOS Safari when a React application is rendered within an element that has the display: contents CSS rule. This issue seems to be specific to iOS, as it works fine on macOS and Windows.

This bug was discovered through a report in the Astro framework. A user noted that a React component became unclickable after a View Transition, which Astro emulates using JavaScript. Upon investigation, I traced the issue to elements with the display: contents rule.

The issue may be related to the trapClickOnNonInteractiveElement hack. When a fake pointerdown listener is added, the bug disappears and everything works correctly. However, I haven't found any documentation on this behavior, so this is just a hypothesis.

React version: 18.3.1

Steps To Reproduce

Render React component with <button onPointerDown={() => console.log('called')}>Click me in an element with display: contents applied. Try clicking the button in iOS Safari.

See this page for reproduction.
See this repository for source code.

The current behavior

onPointerDown listener is not called

The expected behavior

onPointerDown listener should be called

@V3RON V3RON added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Jun 13, 2024
@eps1lon
Copy link
Contributor

eps1lon commented Jun 25, 2024

Can you check if it's just bubbling of pointer events in general i.e. does <div style="display:contents;" onpointerdown="alert(1);"><button>click</button></div> also not work?

Is it only display: contents on the container that is problematic or would it also not work if any intermediate elements have display: contents?

@eps1lon eps1lon added Type: Bug Component: DOM and removed Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug labels Jun 25, 2024
@V3RON
Copy link
Author

V3RON commented Jun 25, 2024

@eps1lon

Can you check if it's just bubbling of pointer events in general i.e. does

click
also not work?

You are right - it doesn't work unless the has a pointer event listener.

Is it only display: contents on the container that is problematic or would it also not work if any intermediate elements have display: contents?

Only the container. It works just fine for intermediate elements.

@eps1lon
Copy link
Contributor

eps1lon commented Jun 25, 2024

Only the container. It works just fine for intermediate elements.

Does this means there's technically a workaround by using a basic div as the container and then rendering root.render(<div style={{ display: "contents" }}><App /></div>) instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants