Fix webview tool output disappearing

This commit is contained in:
Matt Bierner
2026-01-23 15:56:33 -08:00
parent 486c94c384
commit f37cda8a9e
2 changed files with 20 additions and 13 deletions

View File

@@ -165,7 +165,7 @@ export class ChatToolInvocationPart extends Disposable implements IChatContentPa
}
if (isToolResultOutputDetails(resultDetails)) {
return this.instantiationService.createInstance(ChatToolOutputSubPart, this.toolInvocation, this.context);
return this.instantiationService.createInstance(ChatToolOutputSubPart, this.toolInvocation, this.context, this._onDidRemount.event);
}
if (isToolResultInputOutputDetails(resultDetails)) {

View File

@@ -8,6 +8,7 @@ import { renderMarkdown } from '../../../../../../../base/browser/markdownRender
import { decodeBase64 } from '../../../../../../../base/common/buffer.js';
import { CancellationTokenSource } from '../../../../../../../base/common/cancellation.js';
import { Codicon } from '../../../../../../../base/common/codicons.js';
import { Event } from '../../../../../../../base/common/event.js';
import { ThemeIcon } from '../../../../../../../base/common/themables.js';
import { generateUuid } from '../../../../../../../base/common/uuid.js';
import { localize } from '../../../../../../../nls.js';
@@ -41,6 +42,7 @@ export class ChatToolOutputSubPart extends BaseChatToolInvocationSubPart {
constructor(
toolInvocation: IChatToolInvocation | IChatToolInvocationSerialized,
private readonly context: IChatContentPartRenderContext,
private readonly onDidRemount: Event<void>,
@IChatOutputRendererService private readonly chatOutputItemRendererService: IChatOutputRendererService,
@IChatWidgetService private readonly chatWidgetService: IChatWidgetService,
@IInstantiationService private readonly instantiationService: IInstantiationService,
@@ -59,13 +61,15 @@ export class ChatToolOutputSubPart extends BaseChatToolInvocationSubPart {
this.domNode = dom.$('div.tool-output-part');
const titleEl = dom.$('.output-title');
this.domNode.appendChild(titleEl);
if (typeof toolInvocation.invocationMessage === 'string') {
titleEl.textContent = toolInvocation.invocationMessage;
} else {
const md = this._register(renderMarkdown(toolInvocation.invocationMessage));
titleEl.appendChild(md.element);
if (toolInvocation.invocationMessage) {
const titleEl = dom.$('.output-title');
this.domNode.appendChild(titleEl);
if (typeof toolInvocation.invocationMessage === 'string') {
titleEl.textContent = toolInvocation.invocationMessage;
} else {
const md = this._register(renderMarkdown(toolInvocation.invocationMessage));
titleEl.appendChild(md.element);
}
}
this.domNode.appendChild(this.createOutputPart(toolInvocation, details));
@@ -130,12 +134,15 @@ export class ChatToolOutputSubPart extends BaseChatToolInvocationSubPart {
}));
// When the webview is disconnected from the DOM due to being hidden, we need to reload it when it is shown again.
const widget = this.chatWidgetService.getWidgetBySessionResource(this.context.element.sessionResource);
if (widget) {
this._register(widget?.onDidShow(() => {
this._register(this.context.onDidChangeVisibility(visible => {
if (visible) {
renderedItem.reinitialize();
}));
}
}
}));
this._register(this.onDidRemount(() => {
renderedItem.reinitialize();
}));
}, (error) => {
console.error('Error rendering tool output:', error);