Repository navigation
Conversation
|
@rubennorte has imported this pull request. If you are a Meta employee, you can view this in D127796330. |
| expect(onResponderRelease).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| (ReactNativeFeatureFlags.enableNativeEventTargetEventDispatching() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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', { |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
I'd use target: ?EventTarget in case we slip an undefined here from React instead of null.
There was a problem hiding this comment.
Changed to ?EventTarget in 6208d24, also in processResponderEvent. The existing == null check already treats undefined like null.
|
Good catch! Thanks for finding this and submitting a potential fix. Could you please address the comments so we can merge it? |
|
@rubennorte merged this pull request in f754dbd. |
|
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? |
## 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`.
## 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)



Summary:
With
enableNativeEventTargetEventDispatchingon, a touch that ends after its view unmounted never reaches the responder, so the old responder sticks around andtrackedTouchCountstays one too high, which drops the next tap.processResponderEventalready handles a null target, butdispatchNativeEventonly accepts a non-null one and would crash indispatchTrustedEventif it got null. It now takesEventTarget | nulland returns right after the responder step when there is no target. The renderer'sdispatchEvent(ReactFabricEventEmitter.jsin 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.jsthat grants the responder, sendstopTouchEndwith a null target throughdispatchNativeEvent, 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: onmainit throwsTypeError: Cannot read properties of nullfromdispatchTrustedEvent, and it passes with this change.flow check, eslint and prettier are clean.