Skip to content

Commit cce7584

Browse files
committed
fix(message): wrap long words instead of clipping them
1 parent 6a9d5b1 commit cce7584

5 files changed

Lines changed: 26 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"ai-elements": patch
3+
---
4+
5+
Wrap long words in MessageResponse and ReasoningContent instead of clipping them at the message edge

‎packages/elements/__tests__/message.test.tsx‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@ describe("messageResponse", () => {
145145
render(<MessageResponse># Heading</MessageResponse>);
146146
expect(screen.getByText("Heading")).toBeInTheDocument();
147147
});
148+
149+
it("wraps long words instead of letting them overflow", () => {
150+
const { container } = render(
151+
<MessageResponse>{"a".repeat(200)}</MessageResponse>
152+
);
153+
expect(container.firstChild).toHaveClass("break-words");
154+
});
148155
});
149156

150157
describe("messageBranch", () => {

‎packages/elements/__tests__/reasoning.test.tsx‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,16 @@ describe("reasoningContent", () => {
248248
);
249249
expect(container.querySelector(".custom")).toBeInTheDocument();
250250
});
251+
252+
it("wraps long words instead of letting them overflow", () => {
253+
const longWord = "a".repeat(200);
254+
render(
255+
<Reasoning defaultOpen>
256+
<ReasoningContent>{longWord}</ReasoningContent>
257+
</Reasoning>
258+
);
259+
expect(
260+
screen.getByText(longWord).closest(".break-words")
261+
).toBeInTheDocument();
262+
});
251263
});

‎packages/elements/src/message.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ export const MessageResponse = memo(
327327
({ className, ...props }: MessageResponseProps) => (
328328
<Streamdown
329329
className={cn(
330-
"size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",
330+
"size-full break-words [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",
331331
className
332332
)}
333333
plugins={streamdownPlugins}

‎packages/elements/src/reasoning.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export const ReasoningContent = memo(
210210
({ className, children, ...props }: ReasoningContentProps) => (
211211
<CollapsibleContent
212212
className={cn(
213-
"mt-4 text-sm",
213+
"mt-4 break-words text-sm",
214214
"data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 text-muted-foreground outline-none data-[state=closed]:animate-out data-[state=open]:animate-in",
215215
className
216216
)}

0 commit comments

Comments
 (0)