Repository navigation
Conversation
`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, as the Pointer Events specification describes under "Implicit release of pointer capture", and treat a target without a newest clone as no target. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
retargetPointerEventdereferences the result ofgetNewestCloneOfShadowNodewithout a null check (a TODO asks whether that is safe) and crashes for such a target. This can happen today when JavaScript keeps a reference to a removed node that has capture. The processor now releases the capture of a target that has left the tree, as Implicit release of pointer capture describes, and treats a target without a newest clone as no target.The cost is that a capture entry keeps its node revision, and the subtree that revision owns, allocated until an event for that pointer ends the capture:
releasePointerCapture, apointeruporpointercancel, or the first event after the target leaves the tree. If a surface stops during a captured drag and the platform never delivers another event for that pointer id, the entry stays for the life of the runtime. With theweak_ptrsuch an entry held nothing. The processor already keeps more than this in the same case:previousHoverTrackersPerPointer_holds the root node of the tree revision each pointer last hovered, also until the next event for that pointer. Clearing a stopped surface's entries would have to cover the hover trackers and active pointers too, andUIManager::stopSurfacedoes not run on the JavaScript thread that owns the processor, so this PR leaves it out.CaptureTargetOverrideRegistryis declared in a public header and now maps tostd::shared_ptr. This PR updates the three*FrameworksCxx.apisnapshots underscripts/cxx-api/api-snapshotsto match.Changelog:
[GENERAL] [FIXED] - Keep pointer capture when the capturing element re-renders, and release it when the element is removed
Test Plan:
Two cases are added to
PointerEventsProcessorTest:captureOutlivesTheNodeItWasSetOncaptures to a revision that is then released, andcaptureEndsWhenTheTargetLeavesTheTreeremoves the captured node from the tree.Run on this branch (base
94aee19ac9):The C++ tests, built with the Fantom tester's CMake build on this base (2026-11-28):
./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-failurePointerEventsProcessor.cppandPointerEventsProcessor.hfrommainand the new tests kept:captureOutlivesTheNodeItWasSetOnfails andcaptureEndsWhenTheTargetLeavesTheTreecrashes with a segmentation fault; the three existingPointerEventsProcessorTestcases pass.uimanagertests that were built pass, including both new cases. (react_renderer_uimanager_consistency_testswas not built by that target and reports as not run.)🤖 Generated with Claude Code