[Bug]: HTML widgets show on a white canvas in dark themes
Describe the bug
In a dark theme (Dark, Glass, or System on a dark OS), HTML widgets — book interactives and Visualize render_mode=html — show as a bright white panel inside the dark card. The srcdoc document declares no color-scheme, so the browser gives it an opaque light canvas, whatever the app's theme.
Steps to reproduce
- Switch DeepTutor to the Dark theme.
- Open a book page with an interactive block, or run Visualize with an HTML result.
- The widget is a white rectangle with light-scheme form controls.
Expected Behavior
The widget follows the app's theme, like Mermaid diagrams and SVG visualizations already do.
Related Module
web (lib/iframe-html.ts, components/visualize/VisualizationViewer.tsx), widget prompts (agents/visualize/prompts/*/code_generator_agent.yaml rules_html).
Additional Information
Declaring <meta name="color-scheme" content="dark"> in a dark app gives the iframe a transparent canvas over the card. That is the whole host-side fix, but on its own it is not safe: rules_html lets the model "choose layout, color … freely", and many widgets set dark text without a background, relying on the white canvas. Those would become dark-on-dark.
A fix that holds needs both halves:
- The host injects
color-schemematching the resolved theme (lib/theme.ts, re-preparing onsubscribeToThemeChanges) when the widget doesn't declare one. rules_htmltells the model the page is themed by the host: usecolor-scheme-aware colors (Canvas/CanvasText, orprefers-color-scheme/light-dark()), or set an explicit background together with any explicit text color.
We run (1) as a local patch on a dark-only deployment, with (2) written into the workspace instructions; it works there. Happy to send a PR for both once the direction is agreed.
Opened #2683 with the fix in both halves this issue prescribes: the host injects color-scheme into the prepared srcdoc (respecting a widget that declares its own), HtmlRenderer follows the app's resolved palette (Dark/Glass → dark, Snow/light → light, system follows prefers-color-scheme), and rules_html in both en/zh prompts now carries the themed-page rule so generated widgets stop leaning on a white canvas.
Test evidence is in the PR description (1354 node tests, 23 vitest, typecheck/lint/i18n clean, visualize agent tests pass). If your own PR overlaps, happy to fold it in or stand down — the host-side injection is designed to leave self-declared schemes untouched, so widget-authored color-scheme still wins.
Fixed on local dev (2ea5292f9f02acdcc89277fd5012d0476c38eca3). Theme changes and explicit widget themes tested. Web typecheck, 1407 Node tests, eslint and i18n passed.
will be fixed in the next releases!