Skip to content

Process responder events for touches whose target unmounted - #59522

Closed
lazerg wants to merge 2 commits into
react:mainfrom
lazerg:fix/issue-59519-responder-null-target
Closed

lazerg wants to merge 2 commits into
react:mainfrom
lazerg:fix/issue-59519-responder-null-target

Conversation

@lazerg

@lazerg lazerg commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Summary:

With enableNativeEventTargetEventDispatching on, a touch that ends after its view unmounted never reaches the responder, so the old responder sticks around and trackedTouchCount stays one too high, which drops the next tap. processResponderEvent already handles a null target, but dispatchNativeEvent only accepts a non-null one and would crash in dispatchTrustedEvent if it got null. It now takes EventTarget | null and returns right after the responder step when there is no target. The renderer's dispatchEvent (ReactFabricEventEmitter.js in react/react) still skips the call for a null target, so that guard has to go too before the bug is fully fixed, and this change needs to land first.

Fixes #59519

Changelog:

[GENERAL] [FIXED] - Fix the responder not being released when a touch ends after its view unmounted

Test Plan:

Added a Fantom test to ResponderEventTarget-itest.js that grants the responder, sends topTouchEnd with a null target through dispatchNativeEvent, and checks that the release fires and the next touch is granted again. I couldn't build the Fantom runner locally, so I also ran the null-target case as a throwaway Jest test: on main it throws TypeError: Cannot read properties of null from dispatchTrustedEvent, and it passes with this change. flow check, eslint and prettier are clean.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 27, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Oct 27, 2026
@github-actions

Copy link
Copy Markdown

Visual regression

1 visual difference(s) at 2d382197e434. Visual differences need maintainer approval. Review the report, then apply visual-change-approved.

ios scroll-view/horizontal-scroll-to/end: Changed, 69504 px (18.123%)

diff

Expected and Captured
Expected Captured
expected captured

@meta-codesync

meta-codesync Bot commented Oct 27, 2026

Copy link
Copy Markdown

@rubennorte has imported this pull request. If you are a Meta employee, you can view this in D127796330.

expect(onResponderRelease).toHaveBeenCalledTimes(1);
});

(ReactNativeFeatureFlags.enableNativeEventTargetEventDispatching()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the behavior should be the same as before, this test should run for both versions of the feature flag and behave the same way

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left this as is for now because the flag-on run can't pass in this PR alone. With the flag off, a touch end with a null target already goes through the legacy responder plugin and releases the responder. With the flag on, ReactFabric's dispatchEvent drops events with a null target, so they never reach dispatchNativeEvent (react/react#38006). After that guard is removed, the test can run for both flag values with the same expectations. Should I keep it here so it lands with the renderer sync, or add it in a follow-up?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I flipped the gate in 6208d24, so the test now runs with the flag off and is skipped with the flag on. With the flag on, the synced renderer still drops touch events whose target is null before they reach dispatchNativeEvent, so that run can't pass until the renderer sync lands (react/react#38006). I left a TODO on the skip to turn it on after the sync.

expect(onResponderGrant).toHaveBeenCalledTimes(1);

// The target is null when the touched view unmounted during the touch.
dispatchNativeEvent(null, 'topTouchEnd', {

@rubennorte rubennorte Oct 27, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an internal API and we should avoid using them in Fantom tests that should be more e2e. We should find a way to test and verify this using externally visible behaviors (e.g.: dispatching the event while unmounting the component it in the test).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove the dispatchNativeEvent import. This case doesn't need a Fantom API change: I can queue the touch end with Fantom.enqueueNativeEvent, unmount the view, and then flush the queue. The native side then sends the event with a null target, the same as on a device. The flag-on run has the blocker from the other thread, so I'll push this test after we agree on how to handle it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 6208d24. The test now uses only Fantom APIs. It queues the touch end, unmounts the view before the event is flushed, and then checks that a touch on a new view gets the responder.

*/
export default function dispatchNativeEvent(
target: EventTarget,
target: EventTarget | null,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use target: ?EventTarget in case we slip an undefined here from React instead of null.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to ?EventTarget in 6208d24, also in processResponderEvent. The existing == null check already treats undefined like null.

@rubennorte

Copy link
Copy Markdown
Member

Good catch! Thanks for finding this and submitting a potential fix. Could you please address the comments so we can merge it?

@meta-codesync meta-codesync Bot closed this in f754dbd Oct 27, 2026
@meta-codesync meta-codesync Bot added the Merged This PR has been merged. label Oct 27, 2026
@meta-codesync

meta-codesync Bot commented Oct 27, 2026

Copy link
Copy Markdown

@rubennorte merged this pull request in f754dbd.

@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @lazerg in f754dbd

When will my fix make it into a release? | How to file a pick request?

rubennorte pushed a commit to react/react that referenced this pull request Oct 27, 2026
## Summary

With `enableNativeEventTargetEventDispatching` on, the Fabric renderer
skipped `dispatchNativeEvent` when the touched view had already
unmounted, so the touch end never reached the JS responder and the next
tap got lost. This passes the null target through instead, so React
Native can still release the responder. It needs
react/react-native#59522 to land first, since `dispatchNativeEvent`
there throws on a null target today.

Fixes #38006

## How did you test this change?

Added a test in `ReactFabric-test.internal.js` that unmounts a view,
dispatches a touch end to its old instance handle, and expects
`dispatchNativeEvent` to get a null target. It fails on main and passes
with this change. Also ran `yarn test packages/react-native-renderer`
(default, `--prod`, www-modern), `yarn flow fabric`, `yarn linc` and
`yarn prettier-check`.
github-actions Bot pushed a commit to react/react that referenced this pull request Oct 27, 2026
## Summary

With `enableNativeEventTargetEventDispatching` on, the Fabric renderer
skipped `dispatchNativeEvent` when the touched view had already
unmounted, so the touch end never reached the JS responder and the next
tap got lost. This passes the null target through instead, so React
Native can still release the responder. It needs
react/react-native#59522 to land first, since `dispatchNativeEvent`
there throws on a null target today.

Fixes #38006

## How did you test this change?

Added a test in `ReactFabric-test.internal.js` that unmounts a view,
dispatches a touch end to its old instance handle, and expects
`dispatchNativeEvent` to get a null target. It fails on main and passes
with this change. Also ran `yarn test packages/react-native-renderer`
(default, `--prod`, www-modern), `yarn flow fabric`, `yarn linc` and
`yarn prettier-check`.

DiffTrain build for [dc9aed3](dc9aed3)
usama-liaqat pushed a commit to usama-liaqat/react-native that referenced this pull request Nov 14, 2026
)

Summary:
With `enableNativeEventTargetEventDispatching` on, a touch that ends after its view unmounted never reaches the responder, so the old responder sticks around and `trackedTouchCount` stays one too high, which drops the next tap. `processResponderEvent` already handles a null target, but `dispatchNativeEvent` only accepts a non-null one and would crash in `dispatchTrustedEvent` if it got null. It now takes `EventTarget | null` and returns right after the responder step when there is no target. The renderer's `dispatchEvent` (`ReactFabricEventEmitter.js` in react/react) still skips the call for a null target, so that guard has to go too before the bug is fully fixed, and this change needs to land first.

Fixes react#59519

## Changelog:

[GENERAL] [FIXED] - Fix the responder not being released when a touch ends after its view unmounted

Pull Request resolved: react#59522

Test Plan: Added a Fantom test to `ResponderEventTarget-itest.js` that grants the responder, sends `topTouchEnd` with a null target through `dispatchNativeEvent`, and checks that the release fires and the next touch is granted again. I couldn't build the Fantom runner locally, so I also ran the null-target case as a throwaway Jest test: on `main` it throws `TypeError: Cannot read properties of null` from `dispatchTrustedEvent`, and it passes with this change. `flow check`, eslint and prettier are clean.

Reviewed By: javache

Differential Revision: D127796330

Pulled By: rubennorte

fbshipit-source-id: 3c3547998b3b079a540e8cdf8e904ee95a855515
ruslan-volkov added a commit to ruslan-volkov/watchline that referenced this pull request Dec 3, 2026
* Move CI and the project to Node 22 (#100)

Pin Node 22 in .nvmrc and point every workflow's setup-node at it
(CI was still on Node 20), so a local shell, CI and the agent workflows
read one version. Declare engines.node as ^22.13.0 || ^24.0.0: Expo
SDK 58 needs 22.13 or later and does not support odd majors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Upgrade to Expo SDK 55 (React Native 0.83, React 19.2)

Ran `npx expo install expo@^55.0.0 --fix`. Expo packages move to
SDK-major versioning (expo-router 55, expo-notifications 55, ...).

`expo install --fix` can't write to the dynamic app.config.js, so the
config plugins it now wants (expo-font, expo-image, expo-secure-store)
go into app.json by hand.

Babel comment no longer names an SDK: babel-preset-expo adds the
worklets plugin whenever react-native-worklets is installed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Build the e2e simulator app for iOS 16 under Xcode 27

Xcode 27 fails to compile expo-router 55 at SDK 55's iOS 15.1 minimum:
`UIAction.subtitle` resolves to an iOS 16 API in LinkPreviewNativeActionView.
Raising only the pods isn't enough, since the app target then can't import
iOS 16 modules, so the e2e script raises the app target, Podfile platform
and every pod target to 16.0. Only the local simulator build changes; EAS
builds with Xcode 26 and keeps 15.1. SDK 56 raises Expo's minimum to 16.4.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Upgrade to Expo SDK 56 (React Native 0.85, React 19.2.3)

Ran `npx expo install expo@^56.0.0 --fix`, re-pinned expo to ~56.0.24.
Reanimated 4.3, Worklets 0.8, TypeScript 6.0.

`expo install --fix` can't write to the dynamic app.config.js, so the
config plugin it now wants (expo-status-bar) goes into app.json by hand.

jest-expo 56 takes the React Native Jest preset as a peer dependency,
now in its own package: add @react-native/jest-preset matching RN 0.85.

Ran `npx expo-codemod sdk-56-expo-router-react-navigation-replace` over
app/ and src/: nothing to change, we import nothing from @react-navigation.

Not shippable on its own: SDK 56 has a Hermes v1 memory regression with
Reanimated/Worklets that SDK 57 fixes (expo-doctor flags it).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Keep the floating tab bar's blur filling the pill on React Native 0.85

RN 0.85 drops StyleSheet.absoluteFillObject. Spreading it gave only
`overflow: 'hidden'`, so the blur and veil behind the tab icons lost
their absolute fill. The clip style moves to src/theme/layout.ts with a
test and spreads StyleSheet.absoluteFill instead.

Tab icons take `color: ColorValue`, the type expo-router 56 passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Upgrade to Expo SDK 57 (React Native 0.86, Reanimated 4.5, Worklets 0.10)

Ran `npx expo install expo@^57.0.0 --fix`, re-pinned expo to ~57.0.34,
past 57.0.9 (Hermes v1 memory regression fix, RN 0.86.2) and 57.0.17
(dev startup fix, RN 0.86.3). @react-native/jest-preset follows RN to
0.86. No new config plugins wanted. expo-doctor: 21/21.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Drop the e2e script's iOS 16.0 deployment-target override

SDK 56 raises Expo's iOS minimum to 16.4, which the prebuilt app target
and Podfile now carry. The script's override forced 16.0, so it would now
lower the target below what Expo's modules need. The Xcode 27 build of
expo-router needs no workaround at 16.4: the full e2e suite passes
(9/9 flows) without it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Upgrade to Expo SDK 58 (React Native 0.88): prebuild adopts the UIScene life cycle

SDK 58's prebuild generates a SceneDelegate and a UIApplicationSceneManifest, so
dev builds linked against the iOS 27 SDK no longer crash at launch (#99).

- expo 58.1.1, RN 0.88.1, React 19.3, Reanimated 4.7, Worklets 0.13,
  Gesture Handler 3.3, jest 30; @react-native/jest-preset pinned to RN's 0.88.
- engines.node: ^24.3.0 instead of ^24.0.0, the floor Expo 58 and RN 0.88 accept.
- RN 0.88 types: ColorValue now admits null and number, which Ionicons doesn't
  take, and ListHeaderComponent no longer takes null.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Cover watchlinedev:// links through the iOS scene delegate in e2e

Under the scene life cycle a running app gets links in openURLContexts and a
cold start in the scene's connection options. The flow opens one screen each way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Test where a tapped push leads, once per push

Pull the tap handling out of useNotificationRouting into createTapRoutes,
so the tap-to-screen mapping and the cold-start dedupe have a unit test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* State the supported Node versions in the README

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Name the tab icon color helper and the tab bar background style

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Say what the deep-link flow needs, like the other sign-up flows

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Release the JS responder when a touched view unmounts mid-touch

RN 0.88 turns on enableNativeEventTargetEventDispatching by default. The
Fabric renderer then drops a touch event whose target view is gone, so it
never reaches the responder system: the responder stays set and the next
tap goes to it instead of the Pressable. On the recommendations screen the
pull-to-refresh swipe starts on the empty state, the refetch replaces it
with the new row, and the following tap on "Ajouter à ma liste" is lost.

Patch react-native 0.88.1 with the upstream fix (react/react-native#59522,
#59546; 0.88 backport #60467, issue #59519), applied by patch-package on
install. Drop the patch once a 0.88 release ships the backport.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
rubennorte pushed a commit to rubennorte/react-native that referenced this pull request Dec 3, 2026
)

Summary:
With `enableNativeEventTargetEventDispatching` on, a touch that ends after its view unmounted never reaches the responder, so the old responder sticks around and `trackedTouchCount` stays one too high, which drops the next tap. `processResponderEvent` already handles a null target, but `dispatchNativeEvent` only accepts a non-null one and would crash in `dispatchTrustedEvent` if it got null. It now takes `EventTarget | null` and returns right after the responder step when there is no target. The renderer's `dispatchEvent` (`ReactFabricEventEmitter.js` in react/react) still skips the call for a null target, so that guard has to go too before the bug is fully fixed, and this change needs to land first.

Fixes react#59519

[GENERAL] [FIXED] - Fix the responder not being released when a touch ends after its view unmounted

Pull Request resolved: react#59522

Test Plan: Added a Fantom test to `ResponderEventTarget-itest.js` that grants the responder, sends `topTouchEnd` with a null target through `dispatchNativeEvent`, and checks that the release fires and the next touch is granted again. I couldn't build the Fantom runner locally, so I also ran the null-target case as a throwaway Jest test: on `main` it throws `TypeError: Cannot read properties of null` from `dispatchTrustedEvent`, and it passes with this change. `flow check`, eslint and prettier are clean.

Reviewed By: javache

Differential Revision: D127796330

Pulled By: rubennorte

fbshipit-source-id: 3c3547998b3b079a540e8cdf8e904ee95a855515
(cherry picked from commit f754dbd)
rubennorte added a commit that referenced this pull request Dec 3, 2026
…60467)

* Process responder events for touches whose target unmounted (#59522)

Summary:
With `enableNativeEventTargetEventDispatching` on, a touch that ends after its view unmounted never reaches the responder, so the old responder sticks around and `trackedTouchCount` stays one too high, which drops the next tap. `processResponderEvent` already handles a null target, but `dispatchNativeEvent` only accepts a non-null one and would crash in `dispatchTrustedEvent` if it got null. It now takes `EventTarget | null` and returns right after the responder step when there is no target. The renderer's `dispatchEvent` (`ReactFabricEventEmitter.js` in react/react) still skips the call for a null target, so that guard has to go too before the bug is fully fixed, and this change needs to land first.

Fixes #59519

[GENERAL] [FIXED] - Fix the responder not being released when a touch ends after its view unmounted

Pull Request resolved: #59522

Test Plan: Added a Fantom test to `ResponderEventTarget-itest.js` that grants the responder, sends `topTouchEnd` with a null target through `dispatchNativeEvent`, and checks that the release fires and the next touch is granted again. I couldn't build the Fantom runner locally, so I also ran the null-target case as a throwaway Jest test: on `main` it throws `TypeError: Cannot read properties of null` from `dispatchTrustedEvent`, and it passes with this change. `flow check`, eslint and prettier are clean.

Reviewed By: javache

Differential Revision: D127796330

Pulled By: rubennorte

fbshipit-source-id: 3c3547998b3b079a540e8cdf8e904ee95a855515
(cherry picked from commit f754dbd)

* Sync OSS Fabric renderers for null-target native events (#59546)

Summary:

Regenerate the development, production, and profiling Fabric renderer bundles from React revision `dc9aed364252a34966f4f2c4a98272317fdddb60`. Native events whose view has unmounted now reach the responder system even when their event target is null.

This renderer-only update retains React version `19.3.0` and leaves package metadata and dependency versions unchanged.

Changelog:
[General][Fixed] - Fix lost taps after a touched view unmounts when EventTarget event dispatching is enabled

Reviewed By: javache

Differential Revision: D127828293

Pull Request resolved: #59546

(cherry picked from commit eb90a8d)

* Run the unmounted-touch responder test with both dispatch systems (#59545)

Summary:

Remove the flag-dependent skip from the Fantom regression test for a touched view unmounting before its touch ends. Fabric now forwards native events with a null target, so both dispatch systems must release the stale responder and grant the next touch.

Keep the existing `enableNativeEventTargetEventDispatching:*` test matrix and remove the unused feature-flag import and obsolete TODO.

Changelog: [Internal]

___

landed-with-radar-review

Differential Revision: D127828380

Pull Request resolved: #59545

(cherry picked from commit eaf4c26)

---------

Co-authored-by: lazerg <lazerg2@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants