From 5fe8e27136f9d9070fc0dc80ee5f86fa2873243c Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Mon, 2 Dec 2024 05:49:50 +0000 Subject: [PATCH] Fix error when closing inline chat widgets (#234950) Set lastItem before rendering list, chat which may try to reference lastItem Fix #234596 --- src/vs/workbench/contrib/chat/browser/chatWidget.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/chatWidget.ts b/src/vs/workbench/contrib/chat/browser/chatWidget.ts index 1d0211078a925..87a35990ac777 100644 --- a/src/vs/workbench/contrib/chat/browser/chatWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/chatWidget.ts @@ -519,6 +519,8 @@ export class ChatWidget extends Disposable implements IChatWidget { this._onWillMaybeChangeHeight.fire(); + this.lastItem = treeItems.at(-1)?.element; + ChatContextKeys.lastItemId.bindTo(this.contextKeyService).set(this.lastItem ? [this.lastItem.id] : []); this.tree.setChildren(null, treeItems, { diffIdentityProvider: { getId: (element) => { @@ -543,10 +545,6 @@ export class ChatWidget extends Disposable implements IChatWidget { this.layoutDynamicChatTreeItemMode(); } - this.lastItem = treeItems[treeItems.length - 1]?.element; - if (this.lastItem) { - ChatContextKeys.lastItemId.bindTo(this.contextKeyService).set([this.lastItem.id]); - } if (this.lastItem && isResponseVM(this.lastItem) && this.lastItem.isComplete) { this.renderFollowups(this.lastItem.replyFollowups, this.lastItem); } else if (!treeItems.length && this.viewModel) {