Skip to content

Taps are lost after a view unmounts during a touch (enableNativeEventTargetEventDispatching) #59519

Closed

Description

@maartenbreddels

Note

Claude, Anthropic's AI coding agent, wrote this issue and built the reproducer. It acts on behalf of @maartenbreddels, who asked for this report.

Description

With enableNativeEventTargetEventDispatching on (the default in 0.88), a touch that ends on a view that unmounted during the touch never reaches the JS responder system. The responder then keeps a stale responderNode, and trackedTouchCount stays one too high. After that:

  • the next tap on any Pressable is lost (iOS and Android);
  • on iOS, the first tap after typing in a TextInput is lost too. While the count stays above zero, each topSelectionChange lets the field take the JS responder (canTriggerTransfer in ReactNativeResponder.js).

The legacy plugin path (flag off) does not have this bug.

The cause is in the Fabric renderer's dispatchEvent (Libraries/Renderer/implementations/ReactFabric-*.js, from ReactFabricEventEmitter.js in facebook/react):

if (_enableNativeEventTargetEventDispatching)
  null != eventTarget &&
    reactPrivateInterface.dispatchNativeEvent(eventTarget, topLevelType, nativeEvent);

When the view is gone, eventTarget is null, so dispatchNativeEvent and its processResponderEvent call never run. processResponderEvent(topLevelType, eventTarget: EventTarget | null, ...) already handles a null target. It counts the touch end, and it sends responderEnd/responderRelease to the current responder. The legacy path does the same: it passes a null target to the plugins.

We fixed it in our app with this patch. The renderer always calls dispatchNativeEvent, and dispatchNativeEvent runs the responder step for a null target and skips only the EventTarget dispatch:

--- a/Libraries/Renderer/implementations/ReactFabric-prod.js  (same for -dev and -profiling)
     if (_enableNativeEventTargetEventDispatching)
-      null != eventTarget &&
-        reactPrivateInterface.dispatchNativeEvent(
-          eventTarget,
-          topLevelType,
-          nativeEvent
-        );
+      reactPrivateInterface.dispatchNativeEvent(
+        eventTarget,
+        topLevelType,
+        nativeEvent
+      );
--- a/src/private/renderer/events/dispatchNativeEvent.js
 export default function dispatchNativeEvent(
-  target: EventTarget,
+  target: EventTarget | null,
   type: string,
   payload: {[string]: unknown},
 ): void {
   // Process responder events before normal event dispatch.
   processResponderEvent(type, target, payload);
 
+  if (target == null) {
+    rethrowCaughtError();
+    return;
+  }
+
   try {

The same code is still on main in both repos (ReactFabricEventEmitter.js and dispatchNativeEvent.js), so the fix needs a change in facebook/react as well as here.

Steps to reproduce

  1. Clone the reproducer and run it on an iOS simulator: cd ReproducerApp && yarn install && (cd ios && pod install) && yarn react-native run-ios --mode Release.
  2. Tap "Remove me". Its onPressIn unmounts it while the finger is still down.
  3. Tap "Count". Expected: "Tap count: 1". Actual: the count stays 0.
  4. Type in the text field, then tap "Count". Expected: +1. Actual: this tap is lost too (iOS only).

The repo has a Maestro flow for steps 2–4 (maestro test .maestro/repro.yaml). We ran it on an iPhone 17 Pro simulator (iOS 26.5) with a Release build:

Setup Result Count after each of 4 taps (expected 1/2/3/4)
stock 0.88.0 fails (2 of 2 runs) 0 / 1 / 1 / 2
with the patch above (branch with-patch) passes 1 / 2 / 3 / 4
flag off (branch flag-off) passes 1 / 2 / 3 / 4

On an Android emulator (API 36.1, stock 0.88.0), the tap after the unmount is lost too (0 / 1 / 2 / 3), but the TextInput case does not reproduce.

We (Claude and @maartenbreddels) first hit this in a production app after we upgraded to 0.88. A logout button that unmounted its screen on press-in broke the next tap on the login screen.

React Native Version

0.88.0

Affected Platforms

Runtime - iOS, Runtime - Android

Output of npx @react-native-community/cli info

System:
  OS: macOS 26.5.1
  CPU: (10) arm64 Apple M1 Max
  Memory: 136.23 MB / 64.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 24.14.0
    path: ~/.fnm/bin/node
  Yarn: Not Found
  npm:
    version: 11.9.0
    path: ~/.fnm/bin/npm
  Watchman:
    version: 2026.03.09.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 25.5
      - iOS 26.5
      - macOS 26.5
      - tvOS 26.5
      - visionOS 26.5
      - watchOS 26.5
  Android SDK:
    API Levels:
      - "34"
      - "35"
      - "36"
      - "37"
    Build Tools:
      - 34.0.0
      - 35.0.0
      - 36.0.0
      - 36.1.0
      - 37.0.0
    System Images:
      - android-34 | Wear OS 5 ARM 64 v8a
      - android-34 | Google Play ARM 64 v8a
      - android-35-ext15 | Wear OS 5.1 ARM 64 v8a
      - android-35 | Google Play ARM 64 v8a
      - android-36.1 | Google Play ARM 64 v8a
      - android-36 | Google APIs ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2025.1 AI-251.26094.121.2513.14007798
  Xcode:
    version: 26.6/17F113
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.16
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 20.2.0
    wanted: 20.2.0
  react:
    installed: 19.3.0
    wanted: 19.3.0
  react-native:
    installed: 0.88.0
    wanted: 0.88.0
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true

Stacktrace or Logs

No crash. Maestro output on stock 0.88.0:
Assert that "Tap count: 1" is visible... FAILED

MANDATORY Reproducer

https://github.com/maartenbreddels/rn-responder-repro (branch main shows the bug; with-patch and flag-off show the two fixes)

Screenshots and Videos

Video, stock 0.88.0 on the iOS simulator: after "Remove me", the tap on "Count" does nothing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions