From 6f06a61aa8448ee961cf37a93bb0413a86ce3d9f Mon Sep 17 00:00:00 2001 From: LukeParkerDev <10430890+Hona@users.noreply.github.com> Date: Sun, 14 Jun 2026 20:49:53 +0200 Subject: [PATCH] fix(ui): avoid blank streamed code line --- packages/ui/src/components/markdown-stream.test.ts | 12 ++++++++++++ packages/ui/src/components/markdown-stream.ts | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/ui/src/components/markdown-stream.test.ts b/packages/ui/src/components/markdown-stream.test.ts index 3ef9c0f3387..64a635b88d0 100644 --- a/packages/ui/src/components/markdown-stream.test.ts +++ b/packages/ui/src/components/markdown-stream.test.ts @@ -95,4 +95,16 @@ describe("markdown stream", () => { language: "ts", }) }) + + test("does not add a blank line before the first streamed code", () => { + const previous = project(undefined, "```ts\n", true) + const next = project(previous, `${previous.text}const x = 1`, true) + + expect(next.blocks.at(-1)).toEqual({ + raw: "```ts\nconst x = 1", + src: "const x = 1", + mode: "code", + language: "ts", + }) + }) }) diff --git a/packages/ui/src/components/markdown-stream.ts b/packages/ui/src/components/markdown-stream.ts index e260262c380..e1e22fe61a3 100644 --- a/packages/ui/src/components/markdown-stream.ts +++ b/packages/ui/src/components/markdown-stream.ts @@ -70,7 +70,7 @@ export function project(previous: Projection | undefined, text: string, live: bo const suffix = text.slice(previous.text.length) if (!suffix || tail?.mode !== "code" || tail.complete || suffix.includes("```") || suffix.includes("~~~")) return { text, blocks: stream(text, live) } - const separator = previous.text.endsWith("\n") && !tail.src.endsWith("\n") ? "\n" : "" + const separator = tail.src.length > 0 && previous.text.endsWith("\n") && !tail.src.endsWith("\n") ? "\n" : "" return { text, blocks: [