Skip to content

Conversation

Copy link

Copilot AI commented Oct 30, 2025

ElementTouchEvent was passing native DOM Touch objects directly to consumers instead of converting them to PlayCanvas Touch objects. This caused touch.id to return undefined since native touches use touch.identifier.

Changes

  • Import PlayCanvas Touch class in element-input.js
  • Convert native touches in ElementTouchEvent constructor:
    this.touches = Array.from(event.touches).map(t => new Touch(t));
    this.changedTouches = Array.from(event.changedTouches).map(t => new Touch(t));
  • Add test verifying ElementTouchEvent provides PlayCanvas Touch objects with accessible id property

Example

Before this fix:

element.on('touchstart', (event) => {
  console.log(event.touch.id);  // undefined (native Touch uses 'identifier')
});

After this fix:

element.on('touchstart', (event) => {
  console.log(event.touch.id);  // 123 (PlayCanvas Touch exposes 'id')
});
Original prompt

This section details on the original issue you should resolve

<issue_title>ElementTouchEvent uses wrong type for its touches</issue_title>
<issue_description>Hey everyone,

When I try to access the id-field on touches contained within an ElementTouchEvent, I always receive undefined. Upon further inspection, it turns out touches contained within ElementTouchEvent are of the DOM Touch-type rather than ElementTouchEvent.Touch as declared by the most recent PlayCanvas type definitions ([email protected] from NPM).

Here's a screenshot of VSCode showing the type of the touch-field on an ElementTouchEvent:

Image

Here's a confirmation through some debugging that the touch event I receive from my ElementComponent is in fact of type ElementTouchEvent, and that touches contained within are of the DOM Touch-type:

Image

It turns out that element-input.js in the engine just passes the native Touches it receives straight into a new ElementTouchEvent rather than converting them:

Image

Just for clarity, the constructor of ElementTouchEvent doesn't convert the touches either.

I guess either the type definitions pulled from NPM are incorrect, or the touches should have been converted to the appropriate type so that the id-field on touches can be used as expected.

Can someone please address this?
Thanks a bunch! 💪 </issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Fix wrong type for touches in ElementTouchEvent Fix ElementTouchEvent to convert native DOM Touch objects to PlayCanvas Touch objects Oct 30, 2025
Copilot finished work on behalf of willeastcott October 30, 2025 10:05
Copilot AI requested a review from willeastcott October 30, 2025 10:05
@willeastcott willeastcott requested review from a team and removed request for willeastcott October 30, 2025 10:21
@marklundin marklundin requested a review from Copilot October 30, 2025 10:32
Copy link
Contributor

Copilot AI left a comment

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 updates the ElementTouchEvent class to convert native browser Touch objects to PlayCanvas Touch objects, ensuring consistent Touch object types throughout the framework.

Key changes:

  • Modified ElementTouchEvent constructor to wrap native browser Touch objects from event.touches and event.changedTouches arrays into PlayCanvas Touch objects
  • Added import of Touch class from the touch-event module
  • Added comprehensive test coverage for the Touch object conversion behavior

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/framework/input/element-input.js Updated ElementTouchEvent constructor to convert native browser Touch arrays to PlayCanvas Touch objects using Array.from().map()
test/framework/input/element-touch-event.test.mjs Added new test file to verify that ElementTouchEvent properly converts native Touch objects to PlayCanvas Touch objects
Comments suppressed due to low confidence (1)

src/framework/input/element-input.js:286

  • The JSDoc type for the touch parameter is incorrect. It should be {globalThis.Touch} instead of {Touch} because this parameter receives a native browser Touch object (from event.changedTouches[i]), not a PlayCanvas Touch object. The PlayCanvas Touch objects are created from the native touch arrays in lines 297 and 304.
     * @param {Touch} touch - The touch object that triggered the event.

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

@Maksims
Copy link
Collaborator

Maksims commented Oct 30, 2025

That looks like breaking change.

@willeastcott
Copy link
Contributor

@Maksims I think you have to address Copilot directly to suggest to it you think it's a breaking change (it claimed it's backwards compatible).

@Maksims
Copy link
Collaborator

Maksims commented Oct 30, 2025

I don't work with AI, I can clearly see, that public API docs suggest to return PlayCanvas's Touch but in reality it returns native Touch.
It might be simply docs problem, and Copilot thought to fix it.

It will break, as people rely on these touch objects, and that they are native Touch objects, not PlayCanvas's.

@willeastcott
Copy link
Contributor

@Maksims This PR is an experiment to see how useful GitHub Copilot is as resolving an issue. If you don't want to participate in the experiment, feel free to drop out of the convo.

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.

ElementTouchEvent uses wrong type for its touches

3 participants