chat: fix intermittent empty code blocks in chat responses (#308414)

Schedule a deferred editor render at the end of CodeBlockPart.render()
to ensure view lines are painted even when earlier render passes were
dropped (e.g. when isConnected is false during initial render).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Rob Lourens
2026-04-08 09:36:50 -07:00
committed by GitHub
parent eb014b61a9
commit a01c25f482
2 changed files with 17 additions and 1 deletions

View File

@@ -601,12 +601,21 @@ export class View extends ViewEventHandler {
inputLatency.onRenderStart();
if (!this.domNode.domNode.isConnected) {
const model = this._context.viewModel.model;
if (model.uri.scheme === 'vscode-chat-code-block') {
console.warn(`[EditorView] Render dropped: isConnected=false for ${model.uri.toString()}`);
}
return null;
}
const viewPartsToRender = this._getViewPartsToRender();
if (!this._viewLines.shouldRender() && viewPartsToRender.length === 0) {
const viewLinesShouldRender = this._viewLines.shouldRender();
if (!viewLinesShouldRender && viewPartsToRender.length === 0) {
// Nothing to render
const model = this._context.viewModel.model;
if (model.uri.scheme === 'vscode-chat-code-block') {
console.warn(`[EditorView] Render dropped: nothing to render for ${model.uri.toString()}, viewLines.shouldRender=${viewLinesShouldRender}, viewParts=${viewPartsToRender.length}`);
}
return null;
}

View File

@@ -475,6 +475,13 @@ export class CodeBlockPart extends Disposable {
}
this.layout();
// The editor element is typically not yet connected to the live DOM at
// this point (the caller still needs to attach it). Any render pass
// scheduled by setText/setLanguage/layout is silently dropped by the
// editor view when `isConnected` is false. Schedule a deferred render
// so the view lines are painted once the element is in the document.
this.editor.renderAsync(true);
}
reset() {