From 09be92c26deeda58cff658add6f58548a75df8de Mon Sep 17 00:00:00 2001
From: stevenjj33 <75509501+stevenjj33@users.noreply.github.com>
Date: Fri, 23 Oct 2026 08:10:02 +0800
Subject: [PATCH] fix(webui): repaint mermaid diagrams on theme switch
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Review follow-up on #224 (5 comments), plus one adjacent finding.
1. A diagram already on screen did not follow a theme switch: the render
effect read the theme from the DOM port inside the effect, whose
dependencies were only [dom, text]. The app has no reactive theme
store — every theme transition ends as the appearance effect flipping
the dark class on the document element — so the port grows
subscribeDocumentTheme (a class-attribute MutationObserver) and the
theme joins the render dependencies. A redraw keeps the previous SVG
on screen until the new palette is ready, so the fence never flashes
its source text. Browser case switches theme through the real
settings UI with a no-reload witness.
2. The theme option's doc said 'defaults to the app's current theme'
while the code defaults to light; the comment now says what the code
does and why (pure function, no document).
3. Documented why the retained ",
+ ].join("");
+ const clean = sanitizeWebuiMermaidSvg(styled);
+ expect(clean).not.toContain("@import");
+ expect(clean).not.toContain("evil.example");
+ expect(clean).toContain(".edge { fill: red; }");
+ expect(clean).toContain("url(#arrow)");
+ expect(clean).toContain("data:image/svg+xml;base64,PHN2Zw==");
+ });
+
it("leaves an ordinary diagram untouched", () => {
const plain = '';
expect(sanitizeWebuiMermaidSvg(plain)).toBe(plain);