Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(webui): handle undefined language in code blocks
Flinn-Xbdb3a2ded79f
diff --git a/webui/src/components/CodeBlock.tsx b/webui/src/components/CodeBlock.tsxindex fc2e97bc6..52d274c00 100644--- a/webui/src/components/CodeBlock.tsx+++ b/webui/src/components/CodeBlock.tsx@@ -33,7 +33,7 @@ const LazyHighlightedCode = lazy(async () => {default({ language, code, isDark }: HighlightedCodeProps) {return (<SyntaxHighlighter- language={language}+ language={language || "text"}style={isDark ? oneDark : oneLight}customStyle={{margin: 0,diff --git a/webui/src/components/MarkdownTextRenderer.tsx b/webui/src/components/MarkdownTextRenderer.tsxindex 4b43e778d..6f3f19bdf 100644--- a/webui/src/components/MarkdownTextRenderer.tsx+++ b/webui/src/components/MarkdownTextRenderer.tsx@@ -264,7 +264,7 @@ export default function MarkdownTextRenderer({if (fence) {return (<CodeBlock- language={fence.language}+ language={fence.language || "text"}code={fence.code}className="my-3"highlight={highlightCode}diff --git a/webui/src/tests/code-block.test.tsx b/webui/src/tests/code-block.test.tsxindex 7503960ee..4347354d7 100644--- a/webui/src/tests/code-block.test.tsx+++ b/webui/src/tests/code-block.test.tsx@@ -48,6 +48,22 @@ describe("CodeBlock", () => {expect(screen.getByTestId("plain-code-fallback")).toHaveClass("text-foreground/90");});+ it("falls back to 'text' language when language is undefined", async () => {+ render(+ <ThemeProvider theme="dark">+ <CodeBlock language={undefined} code="const value = 1;" />+ </ThemeProvider>,+ );++ await act(async () => {+ await Promise.resolve();+ await Promise.resolve();+ });++ expect(screen.getByTestId("highlighted-code")).toBeInTheDocument();+ expect(screen.getByText("const value = 1;")).toBeInTheDocument();+ });+it("reads theme from context without creating per-block observers", async () => {const originalMutationObserver = globalThis.MutationObserver;const observer = vi.fn();diff --git a/webui/src/tests/markdown-text-renderer.test.tsx b/webui/src/tests/markdown-text-renderer.test.tsxindex e3ff59727..2eb9488f5 100644--- a/webui/src/tests/markdown-text-renderer.test.tsx+++ b/webui/src/tests/markdown-text-renderer.test.tsx@@ -16,6 +16,17 @@ describe("MarkdownTextRenderer", () => {expect(container.querySelector("pre div")).toBeNull();});+ it("renders bare fenced code blocks without crashing", () => {+ const { container } = render(+ <MarkdownTextRenderer highlightCode={false}>+ {"Some text\n\n```\ncode without language\n```"}+ </MarkdownTextRenderer>,+ );++ expect(screen.getByText("code without language")).toBeInTheDocument();+ expect(container.querySelectorAll("pre")).toHaveLength(1);+ });+it("keeps streaming unfinished fenced code blocks to a single shell", () => {const { container } = render(<MarkdownTextRenderer highlightCode={false}>