Skip to content
TypeScript

fix(web): streamed replies render a list's code block as the finished reply does (#28285)

Victor Vogeld05e4f8e8f38
diff --git a/apps/web/src/components/chat/markdownStreamBlocks.test.tsx b/apps/web/src/components/chat/markdownStreamBlocks.test.tsx
index ae81316580b..e3f630feff4 100644
--- a/apps/web/src/components/chat/markdownStreamBlocks.test.tsx
+++ b/apps/web/src/components/chat/markdownStreamBlocks.test.tsx
@@ -31,6 +31,8 @@ describe("splitMarkdownBlocks", () => {
"| a | b |\n| - | - |\n| 1 | 2 |\n\nAfter the table.",
"para\n\n indented code\n\nnext",
"Setext\n===\n\nnext\n---\n\n- [ ] task\n- [x] done",
+ "- a\n\n ```\n x\n\n```\n\nb",
+ "- a\n\n ```\n x\n\ny\n\n ```\n\nb",
])("renders each block as the whole text renders it, at every streamed prefix: %j", (text) => {
for (let end = 0; end <= text.length; end++) {
const source = text.slice(0, end);
diff --git a/apps/web/src/components/chat/markdownStreamBlocks.ts b/apps/web/src/components/chat/markdownStreamBlocks.ts
index 52415ae7197..f0435f2e195 100644
--- a/apps/web/src/components/chat/markdownStreamBlocks.ts
+++ b/apps/web/src/components/chat/markdownStreamBlocks.ts
@@ -14,10 +14,13 @@ export function splitMarkdownBlocks(text: string): string[] | null {
let blockStart = 0;
let lineStart = 0;
let fence: string | null = null;
+ let fenceIndent = 0;
let afterBlankLine = false;
for (const line of text.split("\n")) {
const opener = FENCE_PATTERN.exec(line)?.[1];
if (fence !== null) {
+ // A line left of an indented fence may end the list item holding it, which isn't tracked.
+ if (/\S/.test(line.slice(0, fenceIndent))) break;
if (
opener &&
opener[0] === fence[0] &&
@@ -35,6 +38,7 @@ export function splitMarkdownBlocks(text: string): string[] | null {
}
afterBlankLine = false;
fence = opener ?? null;
+ if (opener) fenceIndent = line.indexOf(opener);
}
lineStart += line.length + 1;
}