Skip to content

Commit 51418f8

Browse files
committed
fix(messages): force markdown re-render on stream completion
1 parent 5c27d09 commit 51418f8

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

src/features/messages/components/MessageRows.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ export const MessageRow = memo(function MessageRow({
360360
)}
361361
{hasText && (
362362
<Markdown
363+
key={`${item.id}-${item.renderVersion ?? 0}`}
363364
value={item.text}
364365
className="markdown"
365366
codeBlockStyle="message"

src/features/threads/hooks/threadReducer/common.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,6 @@ export function mergeStreamingText(existing: string, delta: string) {
115115
if (existing.startsWith(delta)) {
116116
return existing;
117117
}
118-
const maxOverlap = Math.min(existing.length, delta.length);
119-
for (let length = maxOverlap; length > 0; length -= 1) {
120-
if (existing.endsWith(delta.slice(0, length))) {
121-
return `${existing}${delta.slice(length)}`;
122-
}
123-
}
124118
return `${existing}${delta}`;
125119
}
126120

src/features/threads/hooks/threadReducer/threadItemsSlice.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,20 @@ export function reduceThreadItems(state: ThreadState, action: ThreadAction): Thr
7171
const index = list.findIndex((msg) => msg.id === action.itemId);
7272
if (index >= 0 && list[index].kind === "message") {
7373
const existing = list[index];
74+
const prevVersion =
75+
"renderVersion" in existing ? (existing.renderVersion ?? 0) : 0;
7476
list[index] = {
7577
...existing,
7678
text: action.text || existing.text,
79+
renderVersion: prevVersion + 1,
7780
};
7881
} else {
7982
list.push({
8083
id: action.itemId,
8184
kind: "message",
8285
role: "assistant",
8386
text: action.text,
87+
renderVersion: 1,
8488
});
8589
}
8690
const updatedItems = prepareThreadItems(list);

src/styles/messages.css

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,34 @@
11881188
font-size: 0.97em;
11891189
}
11901190

1191+
.markdown table {
1192+
border-collapse: collapse;
1193+
width: 100%;
1194+
margin: 8px 0;
1195+
font-size: 0.92em;
1196+
}
1197+
1198+
.markdown th,
1199+
.markdown td {
1200+
padding: 8px 12px;
1201+
text-align: left;
1202+
border: 1px solid var(--border-subtle);
1203+
}
1204+
1205+
.markdown th {
1206+
background: var(--surface-control);
1207+
font-weight: 600;
1208+
color: var(--text-stronger);
1209+
}
1210+
1211+
.markdown td {
1212+
color: var(--text-muted);
1213+
}
1214+
1215+
.markdown tbody tr:hover {
1216+
background: var(--surface-hover);
1217+
}
1218+
11911219
/* ----- Todo inline ----- */
11921220

11931221
.todo-inline .tool-inline-bar-toggle {

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ export type ConversationItem =
7878
role: "user" | "assistant";
7979
text: string;
8080
images?: string[];
81+
/** Incremented when streaming completes to force markdown re-render */
82+
renderVersion?: number;
8183
}
8284
| { id: string; kind: "reasoning"; summary: string; content: string }
8385
| { id: string; kind: "diff"; title: string; diff: string; status?: string }

0 commit comments

Comments
 (0)