Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix touches being empty in touchEnded() by using changedTouches#8601

Open
suhr25 wants to merge 1 commit intoprocessing:mainfrom
suhr25:fix/touches-empty-in-touchended
Open

Fix touches being empty in touchEnded() by using changedTouches#8601
suhr25 wants to merge 1 commit intoprocessing:mainfrom
suhr25:fix/touches-empty-in-touchended

Conversation

@suhr25
Copy link

@suhr25 suhr25 commented Mar 2, 2026

SUMMARY

Fixes touchEnded() getting an empty touches[].
Now uses changedTouches when touches is empty (per spec).
Changes in src/events/touch.js + a small unit test.


FIX

  • Issue: e.touches is empty on touchend, so loop never runs
  • Fix: fallback to e.changedTouches

Before

for (let i = 0; i < e.touches.length; i++) {

After

const touchList = e.touches.length ? e.touches : e.changedTouches;
for (let i = 0; i < touchList.length; i++) {

VERIFICATION

  • Run tests → should pass
  • Manual test:
function touchEnded() {
  console.log(touches.length);
}

Before: 0
After: 1 (correct final touch)

During a touchend event the W3C Touch Events spec moves the lifted
finger out of e.touches (active contacts only) and into
e.changedTouches. _updateTouchCoords iterated over e.touches.length,
which is 0 when the last finger lifts, so touches[] was always empty
inside touchEnded().

Fall back to e.changedTouches when e.touches is empty so that the
final touch position is accessible to user code in touchEnded().
getTouchInfo already contained the e.touches[i] || e.changedTouches[i]
fallback for individual lookups; this change fixes the loop bound that
prevented it from being reached.

Fixes: touches[] always being [] inside touchEnded() on single-touch
@suhr25
Copy link
Author

suhr25 commented Mar 2, 2026

Hi @davepagurek,
Can you please take a look at this.
Thanks!

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.

1 participant