Skip to content

fix: cancel active touches in onPointerCaptureLost to prevent zombie touch state - #16086

Merged
acoates-ms merged 3 commits into
microsoft:mainfrom
Virtual-Fulfillment-Technologies-Inc:vendora/capture-loss-fix
May 5, 2026
Merged

acoates-ms merged 3 commits into
microsoft:mainfrom
Virtual-Fulfillment-Technologies-Inc:vendora/capture-loss-fix

Conversation

@gmacmaster

@gmacmaster Gordon MacMaster (gmacmaster) commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR fixes a zombie touch state in onPointerCaptureLost: when the OS reclaims pointer capture mid-gesture, entries were never removed from m_activeTouches and no touchcancel was dispatched to React Native JS. The fix applies the copy-then-erase-then-dispatch pattern (already used in onPointerPressed) and also corrects a latent bug where a component tag of 0 would have been silently skipped by the old if (m_pointerCapturingComponentTag) guard.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Why

Touch/pointer sturdiness

What

For each captured pointer in the lost-capture set, copy and erase the
m_activeTouches entry before calling DispatchSynthesizedTouchCancelForActiveTouch,
mirroring the pattern already used in onPointerPressed and onPointerReleased.
The erase-before-dispatch ordering is required because
DispatchSynthesizedTouchCancelForActiveTouch iterates m_activeTouches internally.

Changelog

Should this change be included in the release notes: yes

Fix zombie touch states when OS reclaims the pointer mid-gesture

Microsoft Reviewers: Open in CodeFlow
…touch state (#2)

* fix: cancel active touches in onPointerCaptureLost to prevent zombie touch state

When the OS reclaims pointer capture mid-gesture (system back swipe, Alt+Tab,
  another window coming foreground), onPointerCaptureLost fired but never removed
  entries from m_activeTouches or dispatched a touchcancel to React Native JS.
  The result was a zombie active touch — RN JS believed a finger was still down,
  leaving Pressables and TouchableOpacities stuck in a pressed state until the
  next touch happened to reuse the same pointer ID and trigger the stale-touch
  cleanup in onPointerPressed.

  Fix: for each captured pointer in the lost-capture set, copy and erase the
  m_activeTouches entry before calling DispatchSynthesizedTouchCancelForActiveTouch,
  mirroring the pattern already used in onPointerPressed and onPointerReleased.
  The erase-before-dispatch ordering is required because
  DispatchSynthesizedTouchCancelForActiveTouch iterates m_activeTouches internally.

* match the m_pointerCapturingComponentTag != -1 check already used in CapturePointer
@gmacmaster
Gordon MacMaster (gmacmaster) requested a review from a team as a code owner May 5, 2026 19:49
@acoates-ms

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Contributor
Azure Pipelines successfully started running 1 pipeline(s).
@acoates-ms
acoates-ms merged commit 27d0f96 into microsoft:main May 5, 2026
32 checks passed
acoates-ms pushed a commit that referenced this pull request May 7, 2026
…touch state (#16086) (#16087)

* fix: cancel active touches in onPointerCaptureLost to prevent zombie touch state (#2)

* fix: cancel active touches in onPointerCaptureLost to prevent zombie touch state

When the OS reclaims pointer capture mid-gesture (system back swipe, Alt+Tab,
  another window coming foreground), onPointerCaptureLost fired but never removed
  entries from m_activeTouches or dispatched a touchcancel to React Native JS.
  The result was a zombie active touch — RN JS believed a finger was still down,
  leaving Pressables and TouchableOpacities stuck in a pressed state until the
  next touch happened to reuse the same pointer ID and trigger the stale-touch
  cleanup in onPointerPressed.

  Fix: for each captured pointer in the lost-capture set, copy and erase the
  m_activeTouches entry before calling DispatchSynthesizedTouchCancelForActiveTouch,
  mirroring the pattern already used in onPointerPressed and onPointerReleased.
  The erase-before-dispatch ordering is required because
  DispatchSynthesizedTouchCancelForActiveTouch iterates m_activeTouches internally.

* match the m_pointerCapturingComponentTag != -1 check already used in CapturePointer

* Create react-native-windows-f47bdf2a-0807-483f-b63e-3c2c086bee92.json
acoates-ms added a commit that referenced this pull request May 7, 2026
* Text rendering perf improvement (#16083)

* Minor text rendering perf improvement

* Change files

* fix: map Windows touch pointer IDs to small JS-safe identifiers in CompositionEventHandler (#16081)

* fix: map Windows touch pointer IDs to small JS-safe identifiers in CompositionEventHandler (#1)

* fix: map Windows touch pointer IDs to small JS-safe identifiers in CompositionEventHandler

Windows touch input can assign arbitrarily large pointer IDs (e.g. 2233). The Fabric
  CompositionEventHandler was forwarding these directly as React Native touch identifiers
  via `activeTouch.touch.identifier = pointerId`. React Native's JS touch handler uses
  identifiers as direct array indices and hard-caps them at 20 — large values caused the
  JS layer to back-fill a 2000+ element sparse array, corrupting touch tracking state.

  The symptom: after scrolling a ScrollView/FlatList on a touch screen, Pressables and
  TouchableOpacities would remain stuck in a pressed state. Taps would fire at the
  coordinates where the scroll began rather than where the finger lifted.

  Fix: add `AllocateTouchIdentifier()` which cycles through identifiers [0, 19], skipping
  any slot already claimed by a live touch in `m_activeTouches`. This mirrors the approach
  iOS uses (cycling modulo RCTMaxTouches = 11 in RCTTouchHandler.m). The existing but
  unused `m_touchId` field is repurposed as the cycling base.

  Updated all dependent lookups that previously relied on `touch.identifier == pointerId`
  (which only worked accidentally) to use the `m_activeTouches` map key directly.

  Fixes: #16047

* fix: prevent unbounded m_touchId growth in CompositionEventHandler fallback path

When all 20 touch slots are occupied, the fallback return in
  AllocateTouchIdentifier used post-increment (`m_touchId++ % kMaxTouchIdentifier`),
  which stored the raw incremented value back into m_touchId without a modulo wrap.
  Repeated hits would grow m_touchId past 19, breaking the cycling logic and
  eventually causing signed-integer overflow (UB).

  Fix by computing the wrapped return value first, then storing the next
  wrapped value back: captures fallback = m_touchId % kMaxTouchIdentifier,
  then m_touchId = (m_touchId + 1) % kMaxTouchIdentifier.

* Create react-native-windows-2c040593-f202-44fc-a55c-5d523c493705.json

* Reserve 1 for mouse

* yarn format

* Implement outline properties on view (#16074)

* Implement outline properties on view

* Change files

* hostPlatformColorIsColorMeaningful impl

* update snapshots

* fix background clip

* default black borders should still be rendered.

* fix border sometimes being created behind the background

* snapshots

* fix: cancel active touches in onPointerCaptureLost to prevent zombie touch state (#16086)

* fix: cancel active touches in onPointerCaptureLost to prevent zombie touch state (#2)

* fix: cancel active touches in onPointerCaptureLost to prevent zombie touch state

When the OS reclaims pointer capture mid-gesture (system back swipe, Alt+Tab,
  another window coming foreground), onPointerCaptureLost fired but never removed
  entries from m_activeTouches or dispatched a touchcancel to React Native JS.
  The result was a zombie active touch — RN JS believed a finger was still down,
  leaving Pressables and TouchableOpacities stuck in a pressed state until the
  next touch happened to reuse the same pointer ID and trigger the stale-touch
  cleanup in onPointerPressed.

  Fix: for each captured pointer in the lost-capture set, copy and erase the
  m_activeTouches entry before calling DispatchSynthesizedTouchCancelForActiveTouch,
  mirroring the pattern already used in onPointerPressed and onPointerReleased.
  The erase-before-dispatch ordering is required because
  DispatchSynthesizedTouchCancelForActiveTouch iterates m_activeTouches internally.

* match the m_pointerCapturingComponentTag != -1 check already used in CapturePointer

* Create react-native-windows-f47bdf2a-0807-483f-b63e-3c2c086bee92.json

* Add ability to make TurboModules eager init (#16093)

* Add ability to register modules as eager init

* Change files

* change files

* Fix for non-fabric

* update snapshots

---------

Co-authored-by: Gordon MacMaster <31481849+gmacmaster@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants