Skip to content

Commit e179cef

Browse files
fix(web): collapsed reasoning previews no longer split an emoji (pingdotgg#35677)
1 parent cfad310 commit e179cef

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

‎apps/web/src/components/chat/MessagesTimeline.browser.test.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,6 +1801,10 @@ describe("compact reasoning math", () => {
18011801
"line one\r\nline two\r\n\r\nnext  nbsp wide 😀𝑥
end",
18021802
[["text", "line one line two next nbsp wide 😀𝑥 end"]],
18031803
],
1804+
[
1805+
`${"x".repeat(THOUGHT_PREVIEW_MAX_LENGTH - 1)}😀 tail`,
1806+
[["text", "x".repeat(THOUGHT_PREVIEW_MAX_LENGTH - 1)]],
1807+
],
18041808
["\\$5 and \\$6, \\*not em\\*", [["text", "$5 and $6, *not em*"]]],
18051809
["hard \nbreak\\\nagain", [["text", "hard break again"]]],
18061810
["<div>only html</div>", [["text", "Reasoning"]]],

‎apps/web/src/components/chat/TimelineWorkEntryRow.logic.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,17 +209,20 @@ export function remarkThoughtPreview(fallback: string) {
209209
children.push({ type: "text", value: fragments.join("").replace(/\s+/g, " ") });
210210
fragments = [];
211211
};
212-
const append = (value: string) => {
212+
const take = (value: string) => {
213213
const text = value.slice(0, remaining);
214-
remaining -= text.length;
215-
fragments.push(text);
214+
remaining = text.length < value.length ? 0 : remaining - text.length;
215+
// A cut here or at the source limit must not leave half a surrogate pair.
216+
return text.replace(/[\uD800-\uDBFF]$/, "");
217+
};
218+
const append = (value: string) => {
219+
fragments.push(take(value));
216220
};
217221
const visit = (node: Root | RootContent) => {
218222
if (remaining === 0 || node.type === "html" || node.type === "definition") return;
219223
if (node.type === "math" || node.type === "inlineMath") {
220224
flush();
221-
const value = node.value.slice(0, remaining);
222-
remaining -= value.length;
225+
const value = take(node.value);
223226
children.push({
224227
type: "inlineMath",
225228
value,

0 commit comments

Comments
 (0)