Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/vs/platform/contextkey/browser/contextKeyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,9 @@ class ScopedContextKeyService extends AbstractContextKeyService {
return;
}

// Clear the parent change listener before disposeContext to avoid
// forwarding parent events after this service has begun tearing down.
this._parentChangeListener.clear();
this._parent.disposeContext(this._myContextId);
this._domNode.removeAttribute(KEYBINDING_CONTEXT_ATTR);
super.dispose();
Comment on lines 515 to 517
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This disposal-order fix would be safer with a regression test. There are existing unit tests for ContextKeyService, but none appear to cover that a disposed scoped service stops forwarding parent onDidChangeContext events (and doesn’t contribute to listener leak warnings). Consider adding a test that creates many scoped services, disposes them, then mutates the parent context and asserts no child change events fire / no listeners remain attached.

Suggested change
this._parent.disposeContext(this._myContextId);
this._domNode.removeAttribute(KEYBINDING_CONTEXT_ATTR);
super.dispose();
try {
this._parent.disposeContext(this._myContextId);
this._domNode.removeAttribute(KEYBINDING_CONTEXT_ATTR);
} finally {
super.dispose();
}

Copilot uses AI. Check for mistakes.
Expand Down
Loading