From 3313c8d6ce5698d71480f75404cc3da716d33e98 Mon Sep 17 00:00:00 2001 From: Dotta Date: Fri, 24 Apr 2026 07:36:35 -0500 Subject: [PATCH] Fix rich markdown editor HTML tag crashes --- ui/src/components/MarkdownEditor.test.tsx | 28 +++++++++++++++++++++-- ui/src/components/MarkdownEditor.tsx | 1 + 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/ui/src/components/MarkdownEditor.test.tsx b/ui/src/components/MarkdownEditor.test.tsx index 8aa1b5d2838..c0d6c199ca4 100644 --- a/ui/src/components/MarkdownEditor.test.tsx +++ b/ui/src/components/MarkdownEditor.test.tsx @@ -63,7 +63,7 @@ vi.mock("@mdxeditor/editor", async () => { }), []); React.useEffect(() => { - if (!suppressHtmlProcessing && markdown.includes(""))) { setContent(""); onError?.({ error: "Error parsing markdown: HTML-like formatting requires suppressHtmlProcessing", @@ -262,7 +262,7 @@ describe("MarkdownEditor", () => { await flush(); expect(mdxEditorMockState.markdownValues.at(-1)).toContain("![image](https://example.com/test.png)"); expect(mdxEditorMockState.markdownValues.at(-1)).not.toContain(" { }); }); + it("keeps LLM wrapper tags in the rich editor instead of falling back to raw source", async () => { + const root = createRoot(container); + + await act(async () => { + root.render( + \n## My take\n\nBenchmark notes\n"} + onChange={() => {}} + placeholder="Markdown body" + />, + ); + }); + + await flush(); + expect(mdxEditorMockState.suppressHtmlProcessingValues).toContain(true); + expect(container.querySelector("textarea")).toBeNull(); + expect(container.textContent).toContain("Benchmark notes"); + expect(container.textContent).not.toContain("Rich editor unavailable for this markdown"); + + await act(async () => { + root.unmount(); + }); + }); + it("falls back to a raw textarea when the rich parser rejects the markdown", async () => { mdxEditorMockState.emitMountParseError = true; const handleChange = vi.fn(); diff --git a/ui/src/components/MarkdownEditor.tsx b/ui/src/components/MarkdownEditor.tsx index 888a41a8977..4c604eee450 100644 --- a/ui/src/components/MarkdownEditor.tsx +++ b/ui/src/components/MarkdownEditor.tsx @@ -1084,6 +1084,7 @@ export const MarkdownEditor = forwardRef {