Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/core/src/renderables/Markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ export class MarkdownRenderable extends Renderable {
set streaming(value: boolean) {
if (this._streaming !== value) {
this._streaming = value
// Don't clear parseState - incremental parser handles streaming correctly
this.updateBlocks()
this.requestRender()
// Force a full rebuild on mode transitions to keep table rendering
// correct.
this.clearCache()
}
}

Expand Down
68 changes: 68 additions & 0 deletions packages/core/src/renderables/__tests__/Markdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,74 @@ test("clearCache forces full rebuild", async () => {
expect(parseStateAfter).not.toBe(parseStateBefore)
})

test("streaming->non-streaming transition rebuilds table to show final row", async () => {
const md = new MarkdownRenderable(renderer, {
id: "markdown",
content: "| Value |\n|---|\n| first |\n| second |",
syntaxStyle,
streaming: true,
})

renderer.root.add(md)
await renderOnce()

const tableWhileStreaming = md._blockStates[0]?.renderable

let frame = captureFrame()
.split("\n")
.map((line) => line.trimEnd())
.join("\n")

expect(frame).toContain("first")
expect(frame).not.toContain("second")

md.streaming = false
await renderOnce()

frame = captureFrame()
.split("\n")
.map((line) => line.trimEnd())
.join("\n")

expect(frame).toContain("first")
expect(frame).toContain("second")
expect(md._blockStates[0]?.renderable).not.toBe(tableWhileStreaming)
})

test("non-streaming->streaming transition rebuilds table to hide trailing row", async () => {
const md = new MarkdownRenderable(renderer, {
id: "markdown",
content: "| Value |\n|---|\n| first |\n| second |",
syntaxStyle,
streaming: false,
})

renderer.root.add(md)
await renderOnce()

const tableWhileStable = md._blockStates[0]?.renderable

let frame = captureFrame()
.split("\n")
.map((line) => line.trimEnd())
.join("\n")

expect(frame).toContain("first")
expect(frame).toContain("second")

md.streaming = true
await renderOnce()

frame = captureFrame()
.split("\n")
.map((line) => line.trimEnd())
.join("\n")

expect(frame).toContain("first")
expect(frame).not.toContain("second")
expect(md._blockStates[0]?.renderable).not.toBe(tableWhileStable)
})

test("table only rebuilds when complete row count changes during streaming", async () => {
const md = new MarkdownRenderable(renderer, {
id: "markdown",
Expand Down
Loading