From 2c25bfc8d7bccb3571a6ba7eeb615afee3165bfe Mon Sep 17 00:00:00 2001 From: Isaac Sanchez-Hawkins <266845420+isanchez404@users.noreply.github.com> Date: Wed, 13 May 2026 03:37:11 -0400 Subject: [PATCH] fix(vscode): skip stale active editor broadcasts (#1246) Co-authored-by: Isaac Sanchez --- packages/vscode/src/ChatViewProvider.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/vscode/src/ChatViewProvider.ts b/packages/vscode/src/ChatViewProvider.ts index 0304baba..7e155942 100644 --- a/packages/vscode/src/ChatViewProvider.ts +++ b/packages/vscode/src/ChatViewProvider.ts @@ -389,30 +389,38 @@ export class ChatViewProvider implements vscode.WebviewViewProvider { return; } + const view = this._view; const editor = vscode.window.activeTextEditor; if (!editor || editor.document.uri.scheme !== 'file') { this._scheduleClearActiveEditorFile(); return; } + const editorUri = editor.document.uri; + const editorUriKey = editorUri.toString(); + if (this._clearActiveEditorFileTimer !== undefined) { clearTimeout(this._clearActiveEditorFileTimer); this._clearActiveEditorFileTimer = undefined; } - const filePath = normalizeWindowsDriveLetter(editor.document.uri.fsPath); - const rawFileName = editor.document.uri.fsPath; + const filePath = normalizeWindowsDriveLetter(editorUri.fsPath); + const rawFileName = editorUri.fsPath; const fileName = rawFileName.replace(/\\/g, '/').split('/').pop() || ''; - const relativePath = vscode.workspace.asRelativePath(editor.document.uri, false); + const relativePath = vscode.workspace.asRelativePath(editorUri, false); let fileSize: number | null = null; try { - const stat = await vscode.workspace.fs.stat(editor.document.uri); + const stat = await vscode.workspace.fs.stat(editorUri); fileSize = stat.size; } catch { // File may not be saved yet or inaccessible } + if (this._view !== view || vscode.window.activeTextEditor?.document.uri.toString() !== editorUriKey) { + return; + } + let selection: { startLine: number; endLine: number; text: string } | null = null; if (!editor.selection.isEmpty) { selection = { @@ -428,7 +436,7 @@ export class ChatViewProvider implements vscode.WebviewViewProvider { } this._lastActiveEditorFilePayload = payload; - this._view.webview.postMessage({ + view.webview.postMessage({ type: 'command', command: 'activeEditorFile', payload,