fix(vscode): clean up disposed chat webviews (#1196)
* fix(vscode): clean up disposed chat webviews * fix(vscode): scope disposed webview streams --------- Co-authored-by: Isaac Sanchez <isanchez-hawkins@arize.com>
This commit is contained in:
committed by
GitHub
co-authored by
Isaac Sanchez
parent
51e1967f68
commit
75d78b6113
@@ -45,7 +45,7 @@ export class ChatViewProvider implements vscode.WebviewViewProvider {
|
||||
private _cachedStatus: ConnectionStatus = 'connecting';
|
||||
private _cachedError?: string;
|
||||
private _sseCounter = 0;
|
||||
private _sseStreams = new Map<string, AbortController>();
|
||||
private _sseStreams = new Map<string, { controller: AbortController; view: vscode.WebviewView | undefined }>();
|
||||
private readonly _webviewDevServerUrl: string | null;
|
||||
private _broadcastSelectionDebounce: ReturnType<typeof setTimeout> | undefined;
|
||||
private _clearActiveEditorFileTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
@@ -107,7 +107,23 @@ export class ChatViewProvider implements vscode.WebviewViewProvider {
|
||||
void this._broadcastActiveEditorFile();
|
||||
|
||||
webviewView.onDidDispose(() => {
|
||||
for (const [streamId, stream] of this._sseStreams) {
|
||||
if (stream.view !== webviewView) continue;
|
||||
stream.controller.abort();
|
||||
this._sseStreams.delete(streamId);
|
||||
}
|
||||
if (this._view !== webviewView) return;
|
||||
if (this._broadcastSelectionDebounce !== undefined) {
|
||||
clearTimeout(this._broadcastSelectionDebounce);
|
||||
this._broadcastSelectionDebounce = undefined;
|
||||
}
|
||||
if (this._clearActiveEditorFileTimer !== undefined) {
|
||||
clearTimeout(this._clearActiveEditorFileTimer);
|
||||
this._clearActiveEditorFileTimer = undefined;
|
||||
}
|
||||
this._lastActiveEditorFilePayload = null;
|
||||
this._clearPendingMessages();
|
||||
this._view = undefined;
|
||||
});
|
||||
|
||||
webviewView.webview.onDidReceiveMessage(async (message: (BridgeRequest & { _msgId?: string }) | { type: 'bridge:ack'; _msgId: string }) => {
|
||||
@@ -457,7 +473,7 @@ export class ChatViewProvider implements vscode.WebviewViewProvider {
|
||||
},
|
||||
});
|
||||
|
||||
this._sseStreams.set(streamId, controller);
|
||||
this._sseStreams.set(streamId, { controller, view: this._view });
|
||||
|
||||
start.run
|
||||
.then(() => {
|
||||
@@ -498,9 +514,9 @@ export class ChatViewProvider implements vscode.WebviewViewProvider {
|
||||
const { id, type, payload } = message;
|
||||
const { streamId } = (payload || {}) as { streamId?: string };
|
||||
if (typeof streamId === 'string' && streamId.length > 0) {
|
||||
const controller = this._sseStreams.get(streamId);
|
||||
if (controller) {
|
||||
controller.abort();
|
||||
const stream = this._sseStreams.get(streamId);
|
||||
if (stream) {
|
||||
stream.controller.abort();
|
||||
this._sseStreams.delete(streamId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user