Repository navigation
Conversation
chrfalch
left a comment
There was a problem hiding this comment.
Looks good — the fix addresses the root cause, and both new tests fail without it.
One small request on the description: when the capture target leaves the tree, no lostpointercapture event is delivered (retargeted.target == nullptr in PointerEventsProcessor.cpp). On the web the implicit release fires lostpointercapture at the document; React Native has no document target, so skipping it is reasonable. But the description currently reads as if the capture ends with the normal release semantics. Could you say explicitly that the event is not sent in that case?
|
The description now says that no |
9dcf356 to
970b120
Compare
chrfalch
left a comment
There was a problem hiding this comment.
Thanks for the update, LGTM.
`PointerEventsProcessor` held the node passed to `setPointerCapture`
through a `weak_ptr`. That node is one revision of its element. Once the
element renders again and nothing else owns the old revision, the
pointer expires and the capture ends without a `lostpointercapture`
event. A drag handle that re-renders as the drag starts stops receiving
`pointermove` when the pointer leaves it.
Hold the capture target with a `shared_ptr` until the capture ends.
Events already go to the target's newest clone.
A capture ends only when an event for its pointer is processed, so the
held revision and its subtree stay allocated until then. If a surface
stops during a captured drag and no later event arrives for that
pointer, the entry stays for the life of the runtime. The hover tracker
for the same pointer already holds the root of a tree revision for as
long.
A target that is still owned may have left the tree, and
`retargetPointerEvent` dereferenced the null result of
`getNewestCloneOfShadowNode` for it. Release the capture of a target
that has left the tree at the next event for its pointer, and treat a
target without a newest clone as no target. The Pointer Events
specification releases such a capture and fires `lostpointercapture`
at the document ("Implicit release of pointer capture"). React Native
has no document target and fires no event.
Signed-off-by: James Ide <ide@expo.dev>
970b120 to
bd8d4bc
Compare
Summary:
PointerEventsProcessorholds the node passed tosetPointerCapturethrough aweak_ptr. That node is one revision of its element. Once the element renders again and nothing else owns the old revision, the weak pointer expires and the capture ends without alostpointercaptureevent. A drag handle that re-renders as the drag starts stops receivingpointermovewhen the pointer leaves it.The processor now holds the capture target with a
shared_ptruntil the capture ends. Events already go to the target's newest clone, so they reach the element as it is now.A target that is still owned may have left the tree. On
main,retargetPointerEventdereferences the result ofgetNewestCloneOfShadowNodewithout a null check and crashes for such a target; this can already happen when JavaScript keeps a reference to a removed node that has capture. The processor now treats a target without a newest clone as no target, and ends its capture when it handles the next event for that pointer. Until then,hasPointerCapturestill reports the capture.This follows Implicit release of pointer capture only in part. There, a capture target that is no longer connected loses its capture to the document, and the next processing of pending pointer capture fires
lostpointercaptureat the document. React Native has no document target, so it fires nolostpointercapturewhen a capture ends this way.The cost: a capture entry keeps its node revision, and the subtree that revision owns, allocated until a
pointeruporpointercancelfor that pointer, or the first event for it afterreleasePointerCaptureor after the target leaves the tree. While a capture is set, each event for its pointer also looks up the target's newest clone once more, to check that it is still in the tree. If a surface stops during a captured drag and no later event arrives for that pointer, the entry stays for the life of the runtime.previousHoverTrackersPerPointer_already does more in that case: it holds the root node of the tree revision the pointer last hovered. Clearing a stopped surface's entries is left out:UIManager::stopSurfacedoes not run on the JavaScript thread that owns the processor.CaptureTargetOverrideRegistry, in a public header, now maps tostd::shared_ptr; the three*FrameworksCxx.apisnapshots are updated.Changelog:
[GENERAL] [FIXED] - Keep pointer capture when the capturing element re-renders, and release it when the element is removed
Test Plan:
New cases in
PointerEventsProcessorTest:captureOutlivesTheNodeItWasSetOnandcaptureEndsWhenTheTargetLeavesTheTree../gradlew :private:react-native-fantom:buildFantomTester :private:react-native-fantom:buildReactCommonTests cmake --build private/react-native-fantom/build/tester --target react_renderer_uimanager_tests -j 8 ctest --test-dir private/react-native-fantom/build/tester/react-common-tests -R 'uimanager' --output-on-failureWith
PointerEventsProcessor.cppand.hfrommain, the first fails and the second crashes with a segmentation fault; on this branch theuimanagertests pass. Not run:react_renderer_uimanager_consistency_tests, which that target does not build.