Repository navigation
Don't retain the last KeyboardEvent in ModifierKeyEmitter - #337852
Merged
Dmitriy Vasyura (dmitrivMS) merged 1 commit intoSep 25, 2026
Merged
Conversation
The emitter kept the last modifier KeyboardEvent in its key status. The event references its target and event path, which kept the DOM of e.g. a closed editor or a killed terminal alive until the next modifier key press. Only expose the event while listeners are notified. Related to #146841 Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The leak fix is focused, safely cleared with finally, and covered by a targeted unit test.
Review effort: Balanced
Findings: None
What changed in this PR
Prevents ModifierKeyEmitter from retaining detached DOM through the last keyboard event.
Changes:
- Clears keyboard events after synchronous listener notification.
- Adds regression coverage for event lifetime.
| File | Description |
|---|---|
src/vs/base/browser/dom.ts |
Limits keyboard-event retention to listener dispatch. |
src/vs/base/test/browser/dom.test.ts |
Tests transient event availability. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Dmitriy Vasyura (dmitrivMS)
marked this pull request as ready for review
September 25, 2026 01:35
Dmitriy Vasyura (dmitrivMS)
enabled auto-merge (squash)
September 25, 2026 01:35
roblourens
approved these changes
Sep 25, 2026
Dmitriy Vasyura (dmitrivMS)
deleted the
agents/leak-modifier-key-emitter-event
branch
September 25, 2026 01:45
Abdon Morales (abdonmorales)
pushed a commit
to abdonmorales/vscode-utcs
that referenced
this pull request
Sep 27, 2026
…337852) The emitter kept the last modifier KeyboardEvent in its key status. The event references its target and event path, which kept the DOM of e.g. a closed editor or a killed terminal alive until the next modifier key press. Only expose the event while listeners are notified. Related to microsoft#146841 Co-authored-by: Copilot <[email protected]> (cherry picked from commit 2a4734b)
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Related to #146841
ModifierKeyEmitterstored the last modifierKeyboardEventin its (singleton) key status. AKeyboardEventreferences its target and event path, so the DOM that received the last Ctrl/Alt/Shift/Meta key stayed alive until the next modifier key press — e.g. the complete view DOM of an editor whose model changed or which was closed, or a killed terminal.The event is now only exposed while listeners are notified. Its only consumer (menubar Alt handling) reads it synchronously in the listener.
Retainer path (heap snapshot):
ModifierKeyEmitter.instance → _keyStatus.event → KeyboardEvent → EventPath → <div class="native-edit-context"> → … → <div class="monaco-editor">Measurement
Bounded to one retained tree at a time (replaced on the next modifier key press), but it's the most common way an old editor view stays alive — any keyboard-driven tab switch or close.
How this was measured
Code OSS (Electron, dev build) driven over CDP with Playwright. After each scenario: 4× forced GC, then
DOM.getDetachedDomNodes(the data behind Edge's Detached Elements tool), counting the descendants of every detached root. "Without this change" means all other fixes from this series applied and only this one reverted, so the number shows what this retainer alone keeps alive. Each scenario was run 3 times with identical results. The retainer was identified from a heap snapshot retainer path.Added a unit test that the event is only available while listeners run.