Skip to content

Commit c5b1d98

Browse files
committed
Fix renderTreeSections extra blank line when first section is empty
Track whether any section has been rendered instead of using raw array index to determine separator placement. This prevents unwanted leading blank lines when the first section(s) are empty but later sections have items. Fixes bug where snapshots with only added/removed/renamed images (but no changed ones) would have an extra blank line at the start of the output. Co-Authored-By: Claude Sonnet 4.5 (Anthropic AI Assistant)
1 parent 20c68d8 commit c5b1d98

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎packages/mcp-core/src/tools/snapshot-handlers.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,17 @@ function entryToTreeItem(
270270
function renderTreeSections(
271271
sections: Array<{ title: string; items: SnapshotImageTreeItem[] }>,
272272
): string[] {
273-
return sections.flatMap(({ title, items }, index) => {
273+
let isFirst = true;
274+
return sections.flatMap(({ title, items }) => {
274275
const lines = renderSnapshotImageTreeSection(title, items);
275276
if (lines.length === 0) {
276277
return [];
277278
}
278-
return index === 0 ? lines : ["", ...lines];
279+
if (isFirst) {
280+
isFirst = false;
281+
return lines;
282+
}
283+
return ["", ...lines];
279284
});
280285
}
281286

0 commit comments

Comments
 (0)