Repository navigation
fix: memory leak in native context menu dismissal - #338214
Dmitriy Vasyura (dmitrivMS) merged 5 commits into
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The test fixture’s file URL conversion is broken on Windows.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes native context-menu dismissal leaks by completing the renderer’s one-shot click channel.
Changes:
- Sends a no-selection sentinel when menus close.
- Safely ignores that sentinel in the renderer.
- Adds native Electron lifecycle regression tests.
| File | Description |
|---|---|
electron-main/contextmenu.ts |
Completes click IPC on close. |
electron-browser/contextmenu.ts |
Ignores sentinel values. |
test/electron-main/contextmenu.test.ts |
Runs lifecycle scenarios. |
test/electron-main/fixtures/contextmenu.ts |
Implements native menu fixture. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Windows regression in the new native-menu test fixture The protocol handler in fixtures/contextmenu.ts:38 passes a decoded URL pathname to On Windows, the renderer URL constructed at lines 63-64 has a pathname like Please preserve file-URL escaping and Windows drive semantics when mapping the custom protocol back to a file URL, rather than treating the URL pathname as a filesystem path. I confirmed the transformation with a deterministic Windows Node v24.18.0 round-trip probe: the intended file exists, the fixture-converted path does not, and the standard |
Dmitriy Vasyura (dmitrivMS)
left a comment
There was a problem hiding this comment.
See comment please
|
Removed new (ai generated) e2e tests because they seemed weird, complicated and potentially slow. |
|
Simon Siefke (@SimonSiefke) Thank you! |
Details
Dismissing a native context menu leaves its one-shot click listener and menu actions in the renderer. Removing the callback through the context bridge does not remove the original listener.
Change
Complete the one-shot click channel when the native menu closes, using a no-selection value that the renderer safely ignores. Selected actions still run normally.
Before
Opening an editor tab’s native context menu and dismissing it with Escape 37 times grows per-menu click subscriptions from 5 to 42 and adds 888 MenuItemAction objects.
After
No more leak detected.
Test Video
Seven native context-menu open and Escape dismissal cycles.
test.mp4
AI disclosure: Model: GPT 6 Astra. Worktime: 46 min