Fix disposed store error in DetachedTerminalSnapshotMirror (#289154)

This commit is contained in:
Copilot
2026-01-21 21:31:36 +00:00
committed by GitHub
parent e0d13f0780
commit 2b514ef202
2 changed files with 18 additions and 1 deletions

1
.gitignore vendored
View File

@@ -23,3 +23,4 @@ product.overrides.json
*.tsbuildinfo
.vscode-test
vscode-telemetry-docs/
test-output.json

View File

@@ -576,7 +576,14 @@ export class DetachedTerminalSnapshotMirror extends Disposable {
return getChatTerminalBackgroundColor(theme, this._contextKeyService, storedBackground);
}
}
}).then(terminal => this._register(terminal));
}).then(terminal => {
// If the store is already disposed, dispose the terminal immediately
if (this._store.isDisposed) {
terminal.dispose();
return terminal;
}
return this._register(terminal);
});
}
private async _getTerminal(): Promise<IDetachedTerminalInstance> {
@@ -593,6 +600,9 @@ export class DetachedTerminalSnapshotMirror extends Disposable {
public async attach(container: HTMLElement): Promise<void> {
const terminal = await this._getTerminal();
if (this._store.isDisposed) {
return;
}
container.classList.add('chat-terminal-output-terminal');
const needsAttach = this._attachedContainer !== container || container.firstChild === null;
if (needsAttach) {
@@ -613,6 +623,9 @@ export class DetachedTerminalSnapshotMirror extends Disposable {
return { lineCount: this._lastRenderedLineCount ?? output.lineCount, maxColumnWidth: this._lastRenderedMaxColumnWidth };
}
const terminal = await this._getTerminal();
if (this._store.isDisposed) {
return undefined;
}
if (this._container) {
this._applyTheme(this._container);
}
@@ -625,6 +638,9 @@ export class DetachedTerminalSnapshotMirror extends Disposable {
return { lineCount: 0, maxColumnWidth: 0 };
}
await new Promise<void>(resolve => terminal.xterm.write(text, resolve));
if (this._store.isDisposed) {
return undefined;
}
this._dirty = false;
this._lastRenderedLineCount = lineCount;
// Only compute max column width for small outputs to avoid performance issues