fix(input): pierce shadow DOM in onTouchMove over-canvas detection#7321
Open
pauliojanpera wants to merge 1 commit into
Open
fix(input): pierce shadow DOM in onTouchMove over-canvas detection#7321pauliojanpera wants to merge 1 commit into
pauliojanpera wants to merge 1 commit into
Conversation
InputManager.onTouchMove used document.elementFromPoint() to decide whether a touch is over the canvas. When Phaser runs inside a shadow root, that call resolves to the shadow host rather than the canvas, so `overCanvas` is always false, `isOver` latches false, and every touchmove inside the shadow root is silently dropped — pointer.x/y never update on touch devices. Use the canvas's root node (canvas.getRootNode(), a ShadowRoot when inside shadow DOM, otherwise the Document) which exposes elementFromPoint and resolves the topmost element across the shadow boundary. Falls back to document when the root node has no elementFromPoint.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR
Describe the changes below:
InputManager.onTouchMove used document.elementFromPoint() to decide whether a touch is over the canvas. When Phaser runs inside a shadow root, that call resolves to the shadow host rather than the canvas, so
overCanvasis always false,isOverlatches false, and every touchmove inside the shadow root is silently dropped — pointer.x/y never update on touch devices.Use the canvas's root node (canvas.getRootNode(), a ShadowRoot when inside shadow DOM, otherwise the Document) which exposes elementFromPoint and resolves the topmost element across the shadow boundary. Falls back to document when the root node has no elementFromPoint.
Reproduction
A self-contained, single-file repro that demonstrates the bug:
It mounts a Phaser game whose canvas is created inside an open shadow root and logs two independent event streams: a raw DOM
touchmovelistener on the canvas, and Phaser's ownpointermove. Open the live link and drag inside the dark area on a touch device (or with DevTools touch emulation: Ctrl/Cmd+Shift+M).phaser@3.90.0): the rawtouchmoveevents fire, but Phaserpointermovenever fires for touch, and the status bar turns red — "BUG REPRODUCED". A mouse drag still logspointermove, since the mouse path never callselementFromPoint— so only the touch path is broken.<script src>for a build containing the patchedInputManager.js):touchmoveandpointermovefire together and the status bar turns green.