#55488: fix: release right-clicked nodes after the context-menu event
Description of Change
Fixes #55487.
Electron emits 'context-menu' and leaves the menu to the app, so nothing calls WebContents::NotifyContextMenuClosed the way Chrome's RenderViewContextMenu does when its menu closes. Blink's ContextMenuController then keeps its hit-test result, which holds the right-clicked node and every ancestor, until the next context menu. A page that removes those nodes can't collect them.
This PR calls NotifyContextMenuClosed() right after the event is emitted. Electron shows its own menus and never sends the renderer a custom-item command, so nothing reads that state afterwards. The DevTools path already notifies (devtools_context_menu.cc).
Not covered: right-clicks on selected text. Blink also starts two link-to-text generators over the selection (TextFragmentHandler and AnnotationAgentGenerator), and each keeps the selection's nodes. AnnotationAgentContainer has no browser-side cancel, so that case needs a Blink change, e.g. resetting preemptive generation in ContextMenuController::ClearContextMenu(). It's tracked in #55487.
Tests. The spec right-clicks a full-page node, removes it, forces GC, and checks that a payload attached to the node was collected. On stock Electron 44.1.0 and 45.0.0 the payload stays alive in 3/3 runs, and the control without a right-click collects it. @georgexu99 built main + this change on macOS arm64: the spec passes 3/3, fails 3/3 without the change, and still passes without the window having focus.
I have not built Electron locally (no full Xcode on this machine).
Checklist
- I have built and tested this change
- I have filled out the PR description
- I have reviewed and verified the changes
-
npm testpasses - tests are changed or added
- PR release notes describe the change in a way relevant to app developers, and are capitalized, punctuated, past tense, and no longer than 80 characters.
Release Notes
Notes: Fixed a leak where right-clicked elements stayed alive after removal.
Backports
Semver Impact
Semantic Versioning helps users understand the impact of updates:
- Major (X.y.z): Breaking changes that may require code modifications
- Minor (x.Y.z): New features that maintain backward compatibility
- Patch (x.y.Z): Bug fixes that don't change the API
- None: Changes that don't affect using facing parts of Electron