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
23 changes: 23 additions & 0 deletions packages/streamdown/__tests__/list-item-paragraphs.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { render } from "@testing-library/react";
import { describe, expect, it } from "vitest";
import { Streamdown } from "../index";

describe("list item paragraph wrapping", () => {
it("does not keep paragraph wrappers for loose list items", () => {
const markdown = `
## Test

- hello

- world
`;
const { container } = render(<Streamdown>{markdown}</Streamdown>);

const items = container.querySelectorAll('[data-streamdown="list-item"]');

expect(items).toHaveLength(2);
for (const item of items) {
expect(item.querySelector("p")).toBeNull();
}
});
});
14 changes: 13 additions & 1 deletion packages/streamdown/lib/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,25 @@ type LiProps = WithNode<JSX.IntrinsicElements["li"]>;
const MemoLi = memo<LiProps>(
({ children, className, node, ...props }: LiProps) => {
const cn = useCn();

const childArray = Array.isArray(children)
? children.filter((child) => child !== "\n" && child !== "")
: [children];

const normalizedChildren =
childArray.length === 1 &&
isValidElement(childArray[0]) &&
childArray[0].type === "p"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
childArray[0].type === "p"
childArray[0].type === MemoParagraph

The check childArray[0].type === "p" in MemoLi never matches because hast-util-to-jsx-runtime maps p elements to the MemoParagraph component, making .type the component function rather than the string "p".

Fix on Vercel

? childArray[0].props.children
: children;

return (
<li
className={cn("py-1 [&>p]:inline", className)}
data-streamdown="list-item"
{...props}
>
{children}
{normalizedChildren}
</li>
);
},
Expand Down