Repository navigation
Release the input focus tracker once the input blurs - #337856
Merged
Dmitriy Vasyura (dmitrivMS) merged 3 commits intoSep 25, 2026
Merged
Dmitriy Vasyura (dmitrivMS) merged 3 commits into
Dmitriy Vasyura (dmitrivMS) merged 3 commits into
Conversation
The disposed focus tracker and its listener stayed in the per-focus store until the next focusin event and kept the last focused input element alive, e.g. the edit context of a disposed editor view. Related to #146841 Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The lifecycle cleanup is correct and narrowly scoped; only a minor comment-style issue remains.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Prevents a focused input element from being retained after blur by immediately clearing its focus-scoped disposables.
Changes:
- Clears the focus tracker and one-time blur listener on blur.
- Releases references to disposed input DOM elements.
| File | Description |
|---|---|
src/vs/platform/contextkey/browser/contextKeyService.ts |
Clears input-focus disposables immediately after blur. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot <[email protected]>
Dmitriy Vasyura (dmitrivMS)
marked this pull request as ready for review
September 25, 2026 01:38
Dmitriy Vasyura (dmitrivMS)
enabled auto-merge (squash)
September 25, 2026 01:38
Paul (pwang347)
approved these changes
Sep 25, 2026
Dmitriy Vasyura (dmitrivMS)
deleted the
agents/leak-context-key-input-focus-tracker
branch
September 25, 2026 01:55
Abdon Morales (abdonmorales)
pushed a commit
to abdonmorales/vscode-utcs
that referenced
this pull request
Sep 27, 2026
* Release the input focus tracker once the input blurs The disposed focus tracker and its listener stayed in the per-focus store until the next focusin event and kept the last focused input element alive, e.g. the edit context of a disposed editor view. Related to microsoft#146841 Co-authored-by: Copilot <[email protected]> * Remove narrating comment Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]> (cherry picked from commit ef46e22)
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
ContextKeyService.updateInputContextKeyscreates a focus tracker for the focused input on everyfocusin. When the input blurred, the tracker was disposed, but the disposed tracker and theEvent.oncelistener stayed in the per-focusDisposableStoreuntil the nextfocusin. The tracker's_refreshStateHandlerclosure references the element, so the last focused input stayed alive — e.g. thenative-edit-contextof an editor view that was disposed while focused, when focus didn't move to another element.The store is now cleared once the input blurs.
Retainer path (heap snapshot):
ContextKeyService … onFocusDisposables (MutableDisposable) → DisposableStore → FocusTracker._refreshStateHandler → element → <div class="native-edit-context">Measurement
native-edit-context) + the disposedFocusTrackerSmall: the edit context element is removed from the view on dispose, so only the element itself is retained, not the view. Included for completeness of the #146841 cleanup.
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.