Skip to content

Commit 1137ae3

Browse files
authored
Merge pull request microsoft#107887 from microsoft/alexr00/issue#107801
Listener leak when scrolling PULL REQUESTS view
2 parents 57bc9ae + 87d7c6d commit 1137ae3

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/vs/platform/contextkey/browser/contextKeyService.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ export abstract class AbstractContextKeyService implements IContextKeyService {
328328
public abstract getContextValuesContainer(contextId: number): Context;
329329
public abstract createChildContext(parentContextId?: number): number;
330330
public abstract disposeContext(contextId: number): void;
331-
public abstract updateParent(parentContextKeyService: IContextKeyService): void;
331+
public abstract updateParent(parentContextKeyService?: IContextKeyService): void;
332332
}
333333

334334
export class ContextKeyService extends AbstractContextKeyService implements IContextKeyService {
@@ -423,6 +423,7 @@ class ScopedContextKeyService extends AbstractContextKeyService {
423423
public dispose(): void {
424424
this._isDisposed = true;
425425
this._parent.disposeContext(this._myContextId);
426+
this._parentChangeListener?.dispose();
426427
if (this._domNode) {
427428
this._domNode.removeAttribute(KEYBINDING_CONTEXT_ATTR);
428429
this._domNode = undefined;
@@ -454,7 +455,11 @@ class ScopedContextKeyService extends AbstractContextKeyService {
454455
this._parent.disposeContext(contextId);
455456
}
456457

457-
public updateParent(parentContextKeyService: AbstractContextKeyService): void {
458+
public updateParent(parentContextKeyService?: AbstractContextKeyService): void {
459+
if (!parentContextKeyService) {
460+
this._parentChangeListener?.dispose();
461+
return;
462+
}
458463
const thisContainer = this._parent.getContextValuesContainer(this._myContextId);
459464
const oldAllValues = thisContainer.collectAllValues();
460465
this._parent = parentContextKeyService;

src/vs/platform/contextkey/common/contextkey.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ export interface IContextKeyService {
11391139
createScoped(target?: IContextKeyServiceTarget): IContextKeyService;
11401140
getContext(target: IContextKeyServiceTarget | null): IContext;
11411141

1142-
updateParent(parentContextKeyService: IContextKeyService): void;
1142+
updateParent(parentContextKeyService?: IContextKeyService): void;
11431143
}
11441144

11451145
export const SET_CONTEXT_COMMAND_ID = 'setContext';

src/vs/workbench/contrib/views/browser/treeView.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,9 @@ class TreeMenus extends Disposable implements IDisposable {
10271027
createAndFillInContextMenuActions(menu, { shouldForwardArgs: true }, result, this.contextMenuService, g => /^inline/.test(g));
10281028

10291029
menu.dispose();
1030-
1030+
// When called without a parameter, updateParent will dispose the parent change listener.
1031+
// We cannot call dispose on the contextKeyService because it will break submenus.
1032+
contextKeyService.updateParent();
10311033
return result;
10321034
}
10331035
}

0 commit comments

Comments
 (0)