fix(webui): wrap long inline code in plain paragraphs (#6670)

* fix(webui): wrap long inline code in plain paragraphs

Keep long single-line inline code inside top-level paragraphs flowing with surrounding text while preserving consecutive spaces and tabs.

Apply the same whitespace preservation to short inline code in those paragraphs. Lists, quotes, headings, tables, and multiline code blocks retain their existing behavior.

Refs #6662

* test(webui): load code-wrapping renderer lazily

Keep the shared fixture from eagerly loading MarkdownTextRenderer, so history-boundary tests can defer it without blocking page navigation.

Refs #6662
This commit is contained in:
chenz authored and GitHub committed 2026-11-15 19:03:42 +08:00
1 parent 12a86eaa86
commit 2c669935a5
5 files changed
+306 -3

No files matched your search

+37 -1
View File
@@ -1,7 +1,27 @@
import { useState } from "react";
import { lazy, Suspense, useState } from "react";
import { MessageBubble } from "@/components/MessageBubble";
// Keep this lazy: history-boundary tests hold the renderer request while the fixture loads.
const MarkdownTextRenderer = lazy(() => import("@/components/MarkdownTextRenderer"));
const outsideCode = `begin \t${"word ".repeat(25)}end`;
const inlineSource = [
`Before \`${"word ".repeat(23)}wordx\` after.`,
`Before \`${"word ".repeat(24)}x\` after.`,
`Spaces \`begin \t${"word ".repeat(30)}end\` after.`,
`Token \`${"x".repeat(180)}\` after.`,
`CJK \`${"中文".repeat(70)}\` after.`,
"Short `one \ttwo` after.",
`Link [\`${"x".repeat(180)}\`](https://example.com) after.`,
`| Identifier | One | Two | Three | Four | Five |\n| --- | --- | --- | --- | --- | --- |\n| ${"identifier".repeat(4)} | \`default\` | \`release\` | \`private\` | \`enabled\` | \`compact\` |`,
`\`\`\`text\n${"f".repeat(180)}\nsecond line\n\`\`\``,
` ${"i".repeat(180)}\n indented line two`,
`| Label | Code |\n| --- | --- |\n| Long | \`${outsideCode}\` |`,
`## Heading \`${outsideCode}\``,
`- List \`${outsideCode}\``,
].join("\n\n");
const source = [
"# Environment",
"",
@@ -13,6 +33,8 @@ const source = [
export function CodeWrappingFixture() {
const [code, setCode] = useState(source);
const [streaming, setStreaming] = useState(true);
const [inlineMessage, setInlineMessage] = useState("Before `");
const [inlineStreaming, setInlineStreaming] = useState(true);
return <main className="mx-auto max-w-3xl space-y-4 p-4">
<textarea aria-label="Code source" className="h-24 w-full font-mono text-code" value={code}
onChange={event => setCode(event.target.value)} />
@@ -21,5 +43,19 @@ export function CodeWrappingFixture() {
id: "wrapped-code", role: "assistant", createdAt: 1, isStreaming: streaming,
content: `\`\`\`markdown\n${code}\n\`\`\``,
}} />
<section data-testid="inline-code-wrapping">
<Suspense fallback={null}>
<MarkdownTextRenderer streaming={streaming} highlightCode={false}>{inlineSource}</MarkdownTextRenderer>
</Suspense>
</section>
<textarea aria-label="Inline message source" value={inlineMessage}
onChange={event => setInlineMessage(event.target.value)} />
<button onClick={() => setInlineStreaming(false)}>Complete inline message</button>
<section data-testid="inline-message-wrapping">
<MessageBubble message={{
id: "inline-code", role: "assistant", createdAt: 1, isStreaming: inlineStreaming,
content: inlineMessage,
}} />
</section>
</main>;
}