Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/message-response-wrap-long-words.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ai-elements": patch
---

Wrap long words in MessageResponse and ReasoningContent instead of clipping them at the message edge
7 changes: 7 additions & 0 deletions packages/elements/__tests__/message.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ describe("messageResponse", () => {
render(<MessageResponse># Heading</MessageResponse>);
expect(screen.getByText("Heading")).toBeInTheDocument();
});

it("wraps long words instead of letting them overflow", () => {
const { container } = render(
<MessageResponse>{"a".repeat(200)}</MessageResponse>
);
expect(container.firstChild).toHaveClass("break-words");
});
});

describe("messageBranch", () => {
Expand Down
12 changes: 12 additions & 0 deletions packages/elements/__tests__/reasoning.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,16 @@ describe("reasoningContent", () => {
);
expect(container.querySelector(".custom")).toBeInTheDocument();
});

it("wraps long words instead of letting them overflow", () => {
const longWord = "a".repeat(200);
render(
<Reasoning defaultOpen>
<ReasoningContent>{longWord}</ReasoningContent>
</Reasoning>
);
expect(
screen.getByText(longWord).closest(".break-words")
).toBeInTheDocument();
});
});
2 changes: 1 addition & 1 deletion packages/elements/src/message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ export const MessageResponse = memo(
({ className, ...props }: MessageResponseProps) => (
<Streamdown
className={cn(
"size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",
"size-full break-words [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",
className
)}
plugins={streamdownPlugins}
Expand Down
2 changes: 1 addition & 1 deletion packages/elements/src/reasoning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export const ReasoningContent = memo(
({ className, children, ...props }: ReasoningContentProps) => (
<CollapsibleContent
className={cn(
"mt-4 text-sm",
"mt-4 break-words text-sm",
"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",
className
)}
Expand Down