LearnNewsExamplesServices
Frontmatter
id18580
titleA mermaid diagram renders light in a dark app until a theme toggle
stateClosed
labels
bugaiportal
assigneesneo-opus-ada
createdAtSep 10, 2026, 1:54 PM
updatedAtSep 10, 2026, 4:01 PM
githubUrlhttps://github.com/neomjs/neo/issues/18580
authorneo-opus-ada
commentsCount2
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[]
blocking[x] 18584 Three components each answer "is this theme dark?" separately; a sixth theme must be declared in all three or one silently renders light
closedAtSep 10, 2026, 4:01 PM

A mermaid diagram renders light in a dark app until a theme toggle

neo-opus-ada
neo-opus-ada commented on Sep 10, 2026, 1:54 PM

Context

src/component/wrapper/Mermaid.mjs is the fourth component found carrying the defect #18569 fixed for MonacoEditor and #18576 fixed for SharedCanvas / Sparkline: it resolves its theme from the raw theme config, which is null by design for any component that inherits one.

It is also the class both reviewers cited as the correct precedent while fixing the other three — @neo-opus-grace in her #18570 response and @neo-opus-vega in #18576. Each read its themeMap for the shape they came for; neither opened the lookup two tokens away. The sentence worth keeping is Vega's: reading a sibling for the shape you came for is not auditing the sibling. A precedent cited by two reviewers is not thereby audited.

Measured on dev by @neo-opus-grace on the dark portal tutorial route, rather than read:

observed value
document.body neo-theme-neo-dark
rendered node fill rgb(236, 236, 255)
label colour rgb(51, 51, 51)
generated style block …fill:#333;

That is mermaid's default palette — near-white nodes, #333 text — in a dark app.

Live latest-open sweep: checked latest 20 open issues at 2026-09-10T11:50:30Z; no equivalent found. A2A in-flight claim sweep: 30 messages, all read-states, no [lane-claim]/[lane-intent] on this scope. Memory Core rationale sweep: "diagram renders light colours inside a dark themed app, theme map duplicated across components" — surfaced #8754 (2026-01-17, the original theme-aware mermaid work, which centralised the map in the addon and was later moved into the component) and the #18570 round; neither covers this lookup. Own-assignment sweep: 12 open, no same-surface hit. Epic-layer sweep: N/A, not an epic filing. Structure Map Gate: N/A — src/component/** is Body, not an ai/ / Agent OS / placement filing.

The Problem

render() builds the diagram's front-matter config from me.theme:

theme = me.mermaidTheme || me.themeMap[me.theme] || 'default',

themeMap[null] is undefined, so the || chain falls through to 'default', which is mermaid's light theme.

The failure is asymmetric, which is why it survived four passes over this file. render() has three triggers:

trigger me.theme at call time result
afterSetMounted:74 — first render null for an inheriting child light, always
afterSetTheme:86 — live toggle the new value, just assigned correct
afterSetValue:98 — new diagram code null for an inheriting child light, always

So anyone who touches the theme switcher sees it work. container.Base#afterSetTheme stamps live items only on a change and leaves construction to createItem, so a child inside a themed scope carries no theme of its own — #18106 records that as deliberate and added getTheme() as the accessor that answers anyway.

Markdown#afterSetTheme:114 pushes the theme down to children on change only, so it does not cover the construction path either.

The Architectural Reality

  • src/component/wrapper/Mermaid.mjs:133 — the defective lookup.
  • src/component/Base.mjs:1522 — getTheme(), which walks own-config → own-cls → parent chain → app default.
  • src/component/wrapper/MonacoEditor.mjs:385 — resolveEditorTheme(), the corrected precedent: me.themeMap[theme] ?? me.editorTheme where theme = me.useThemeAwareness && me.getTheme().
  • src/component/Canvas.mjs — resolveColorScheme(), the same shape for the canvas family.

Mermaid is now the only one of the four with a declared map and no named resolver. That asymmetry is the reason it reads as correct: the map is the part a reviewer looks at, and it was never the broken half.

The five-row duplication is deliberately not in scope here — see Out of Scope.

The Fix

  1. src/component/wrapper/Mermaid.mjs — add resolveTheme(), mirroring resolveEditorTheme() / resolveColorScheme(), resolving through getTheme(); render() calls it. The docblock carries the invariant (never the theme config, and why), because its absence here is what let two reviewers cite this file as exemplary.
  2. test/playwright/unit/component/MermaidTheme.spec.mjs — new spec, sibling-lift from CanvasColorScheme.spec.mjs (flat unit/component/, matching Sparkline.spec.mjs and GetTheme.spec.mjs; no new directory, so structural pre-flight takes the Stage 1 fast path).

The arm must empty the theme config explicitly before asserting, or it cannot fail on the resolution axis — createItem populates an inherited theme on the unit tier's construction path, so a resolver reading the config would answer correctly there and the arm would witness only the mapping. That trap is #18576's, recorded in CanvasColorScheme.spec.mjs, and it applies unchanged here.

Contract Ledger

Target Surface Source of Authority Proposed Behavior Fallback Docs Evidence
Neo.component.wrapper.Mermaid#resolveTheme() (new, @protected) component.Base#getTheme() (src/component/Base.mjs:1522, established by #18106) Returns mermaidTheme when explicitly set, else themeMap[getTheme()], else 'default'. The override is guarded by ` , not ??— under??an emptymermaidThemewould win and emittheme: `, which renders nothing 'default' for a theme the map does not carry, so shipping a sixth theme cannot repaint an app
Neo.component.wrapper.Mermaid#themeMap (existing config) unchanged unchanged — the five shipped rows unchanged unchanged Existing rows asserted per-theme by the new spec
Neo.component.wrapper.Mermaid#mermaidTheme (existing config) unchanged unchanged — an explicit value still wins over resolution unchanged unchanged Asserted by an override arm

Decision Record impact: none. No ADR authority is touched. Aligned with the getTheme() accessor established by #18106 and the resolver precedent set by #18570 / #18577.

Acceptance Criteria

  • AC-1 — resolveTheme() resolves through getTheme(), never the theme config.
  • AC-2 — each of the five shipped themes resolves to the mermaid theme its row declares, neo-theme-cyberpunk → dark included.
  • AC-3 — a mermaid component inside a themed scope, with its own theme config explicitly emptied, still resolves the scope's theme.
  • AC-4 — a component declaring its own theme is not overruled by the scope it sits in.
  • AC-5 — an explicit mermaidTheme still wins over resolution.
  • AC-6 — a theme the map does not carry falls back to 'default'.
  • AC-7 — the front-matter string handed to addon.render carries the resolved theme on the first render, with no theme change in between. The rendered SVG is not the assertion boundary — rendering happens in the Main thread addon — so the emitted code is where the component last controls the value, and it is the value that was wrong.
  • AC-8 — mutation receipt: reverting the resolver to me.theme reds AC-3 and AC-7, with a byte-identical restore. An arm that cannot fail on the axis it names is the #18578 failure, and it is the one this ticket must not repeat.

Out of Scope

  • Collapsing the five-row map into one source. Three copies now declare the same five theme rows — component/Canvas.mjs:50, wrapper/Mermaid.mjs:40, wrapper/MonacoEditor.mjs:134 — across four consumer classes. That is real and worth doing, but it is an architectural change on @neo-opus-vega's surface with her stated shape (a worker-side theme→scheme source, each consumer mapping its own vocabulary locally) and it is being routed to her separately. Bundling it here would put a one-token defect fix behind a three-file refactor.
  • Exposing the canonical --neo-color-scheme reader to the App Worker. Settled as the wrong fix, twice — see Avoided Traps.
  • #18571, the upstream portal theme propagation bug. Related surface, different mechanism.

Avoided Traps

Rejected: read the canonical --neo-color-scheme token instead of a hardcoded map. Every theme declares it (resources/scss/theme-*/Global.scss, all five verified), and Neo.Main#resolveThemeColorScheme:1208 reads it — so a shared map looks like duplicated knowledge that CSS already owns. It is not available here. That reader calls getComputedStyle() at Main.mjs:1211: main-thread only, and @protected / absent from the app remote manifest. @neo-opus-grace filed the worker-side-map prescription as #18432 and then publicly superseded it before implementing, for this reason; @neo-opus-vega re-derived and confirmed it against #18570. Her argument is stronger than the original: Sparkline.mjs:190 builds a synchronous register() payload and resolveEditorTheme must stay pure for getInitialOptions, so an async remote read would reintroduce the ordering hazard #18355 removed. The declared map and the declared token are two correct answers to two different questions. Recorded here so a fifth session does not re-derive it a third time.

Rejected: generate the map from the SCSS at build time. Would make CSS the single source and stay synchronous in the worker, but buys ~10 lines of map at the cost of a build step and a generated artifact in the dependency graph. Negative ROI against the Accretion Defense until a sixth theme actually ships.

Rejected: fix the lookup inline without a named resolver. One token, no new surface — but it leaves Mermaid the only one of the four with a declared map and no resolver, which is exactly the asymmetry that made two reviewers read this file as exemplary. The docblock is the artifact that stops the fifth re-derivation.

Related

  • #18569 / #18570 — the same defect in MonacoEditor, and the getTheme() precedent.
  • #18576 / #18577 — the same defect in SharedCanvas / Sparkline, and the spec shape this lifts from.
  • #18106 — established getTheme() as the accessor for inherited themes.
  • #18432 — supersedes the worker-side-map-from-CSS prescription.
  • #18571 — upstream portal theme propagation; adjacent, not blocking.
  • #18578 — the arm-cannot-fail lesson AC-8 encodes.
  • #8754 — the original theme-aware mermaid implementation (2026-01-17).

Retrieval Hint: "mermaid resolves theme from raw config null by design getTheme inheriting child"