LearnNewsExamplesServices
Frontmatter
id18576
titleSharedCanvas and Sparkline theme off a config that is null by design
stateClosed
labels
bugaiarchitecturecore
assigneesneo-opus-vega
createdAtSep 10, 2026, 1:44 AM
updatedAtSep 10, 2026, 6:26 AM
githubUrlhttps://github.com/neomjs/neo/issues/18576
authorneo-opus-vega
commentsCount0
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[]
blocking[]
closedAtSep 10, 2026, 6:26 AM

SharedCanvas and Sparkline theme off a config that is null by design

Closed v13.2.0/archive-v13-2-0-chunk-20 bugaiarchitecturecore
neo-opus-vega
neo-opus-vega commented on Sep 10, 2026, 1:44 AM

Context

Found while reviewing #18570, which repairs this exact pair of defects in component/wrapper/MonacoEditor. The same two live in two more components. Captured first as a defect-note to AGENT:*; promoted here because the sighting is independent of the PR that surfaced it and the fix pattern is now proven twice in-tree.

The Problem

Neo.app.SharedCanvas and Neo.component.Sparkline each carry both halves of #18569, and either alone renders a light canvas inside a dark app.

Half one — they read the raw theme config, which is null by design. component/Base.mjs:269 defaults theme_ to null, and #18111's getTheme() docblock records why: "a child inside a themed scope carries no theme class of its own by design". A component that inherits its theme never populates that config.

// src/app/SharedCanvas.mjs:63 — afterSetIsCanvasReady
let mode = this.theme?.includes('dark') ? 'dark' : 'light';

// src/component/Sparkline.mjs:190 — at renderer registration
theme: me.theme?.includes('dark') ? 'dark' : 'light',

The optional chain makes it silent: null?.includes(...) is undefined, undefined is falsy, the ternary answers 'light'. A dark app gets a light canvas and nothing reports an error.

The afterSetTheme halves have the matching gate:

// src/app/SharedCanvas.mjs:124
if (value && this.isCanvasReady) { … }

// src/component/Sparkline.mjs:119
if (me.offscreenRegistered && value) { … }

container.Base#afterSetTheme propagates to live items on a change and leaves construction to createItem, so these fire on a theme toggle and never on first render. That asymmetry is why the defect survives casual use: it works for anyone who interacts with it and fails for everyone who only loads the page.

Half two — the name is not the answer. src/Main.mjs:1199 states the contract in the engine's own words:

"Every theme states its own scheme as --neo-color-scheme in its Global.scss, because the name cannot be trusted to carry it: theme-cyberpunk is dark and is named neither."

Measured: resources/scss/theme-cyberpunk/Global.scss declares --neo-background-color: #0d1117 and --neo-color-scheme: dark, and 'neo-theme-cyberpunk'.includes('dark') is false. All five shipped themes declare the token, one declaration each, no disagreement.

The Architectural Reality

Two in-tree precedents, both correct, both reachable from these files:

  • src/component/wrapper/Mermaid.mjs:39 — a themeMap config mapping all five shipped themes onto the library's own names, cyberpunk included. Being a config rather than a constant lets a consumer extend it for a theme Neo does not ship.
  • src/component/wrapper/MonacoEditor.mjs at #18570's head — resolves through getTheme() and maps through a themeMap, with the resolver kept pure so the creation path can build a correct instance instead of repainting one.

Do not "fix" this by exposing the canonical reader to the App Worker. That prescription was already raised and superseded on #18432: "The author's pre-implementation correction supersedes the original worker-side map prescription. The schemes already exist in component theme declarations, and the value is needed by Main.windowOpen on the main thread where computed CSS is available." Neo.Main#resolveThemeColorScheme (src/Main.mjs:1208) is @protected and absent from the app remote manifest, and the reason is sound: the token lives in CSS on the main thread, so a worker-side read is an async round trip. Both call sites here need the answer synchronously at registration — Sparkline.mjs:190 builds a register() payload — so an async resolution would reintroduce exactly the creation-time ordering hazard #18355 removed by deleting its timeout(150).

The declared map is the right answer for a worker-side consumer. The canonical token is the right answer for the main thread. Both already exist; this ticket adopts the first.

The Fix

Per component, mirroring MonacoEditor at #18570:

  1. Resolve through getTheme() rather than the theme config, at the hook and at the registration/ready site.
  2. Map through a themeMap config rather than a substring test.
  3. Drop the value && / me.theme?. guards that exist only because the config was expected to carry the answer.

Contract Ledger Matrix

Target Surface Source of Authority Proposed Behavior Fallback Docs Evidence
SharedCanvas#afterSetIsCanvasReady src/app/SharedCanvas.mjs:63 resolves via getTheme() + themeMap unmapped theme keeps today's 'light' JSDoc null?.includes() → undefined → 'light'
SharedCanvas#afterSetTheme :124 same; gate no longer needs value unchanged on unmapped JSDoc fires on toggle only today
Sparkline#afterSetTheme src/component/Sparkline.mjs:119 same unchanged on unmapped JSDoc offscreenRegistered && value
Sparkline renderer registration :190 resolved theme in the register() payload 'light' as today JSDoc synchronous payload — no async resolution
themeMap config (new, ×2) Mermaid.mjs:39 precedent five shipped themes; consumer-extensible absent key → today's default JSDoc cyberpunk → dark

Decision Record impact

none — two consumers call the wrong accessor and guess where a declared answer exists. No wire format, no new API, no ADR authority touched.

Acceptance Criteria

  • AC-1 In a dark app, a canvas created under a themed host hands its renderer 'dark' in the first payload it sends, with no theme change in between. This is the half that fails today; a toggle-only witness would pass against the current code.
    ⚠️ Corrected during implementation, and the correction is a narrowing. This AC first said "render dark on first paint". The rendered pixel is unreachable by construction, not merely unreached: main/DomAccess.mjs:944 hands the node to the worker with transferControlToOffscreen(), after which the owning thread cannot read it. The registration payload is the last value the component controls and is exactly the value that was wrong, so it is the honest boundary. Recorded here rather than quietly asserted at a lower bar.
  • AC-2 ⚠️ Both directions, on the same instance. Light host → light, dark host → dark. An arm that only checks dark passes against a component hardcoded dark.
  • AC-3 neo-theme-cyberpunk renders dark in both components. This is the arm that distinguishes a map from a substring test, and it reds if anyone reintroduces includes('dark').
  • AC-4 An unmapped theme falls back to today's value rather than guessing, so adding a theme cannot silently flip an existing app.
  • AC-5 Neither component reads the raw theme config for this decision any more: grep -n "theme?.includes\|value.includes('dark')" src/app/SharedCanvas.mjs src/component/Sparkline.mjs returns zero.

Out of Scope

  • component/Base.mjs#getTheme() and theme propagation — the resolver is correct and already returns the right answer to both callers.
  • Exposing resolveThemeColorScheme to the App Worker — superseded on #18432, and the synchronous-registration constraint above makes it worse here than there.
  • MonacoEditor — repaired by #18570; this ticket is the other two consumers.
  • Any change to the --neo-color-scheme token or its main-thread reader.

Avoided Traps

  • Do not propagate theme down so the config stops being null. #18111 records the null as deliberate and removed exactly that behaviour.
  • Do not resolve the scheme asynchronously. Sparkline.mjs:190 builds a synchronous register() payload; an await there reintroduces the ordering hazard #18355 removed.
  • Do not assert the worker-side config and call it covered. #18569 measured a correct config that never reached the DOM; the arm has to read what renders.
  • Do not extend includes('dark') with more names. The map is the point — a two-way name guess cannot express a theme whose name carries nothing, which is the whole finding.

Related

  • #18569 / #18570 — the same pair of defects in MonacoEditor, and the fix this ticket mirrors.
  • #18432 / PR #18436 — established --neo-color-scheme as the declared truth, and superseded the worker-side prescription.
  • #18111 / #18106 — getTheme() and the null-by-design contract.
  • #8845 / #8727 — where includes('dark') was first authored, when the shipped themes were only light and dark.

Sweeps. Live latest-20 open sweep at 2026-09-09T23:41:02Z — no equivalent; nearest are #18569 (the same defect in a third component, being fixed) and #18571 (portal theme propagation, a different layer). All-state search on the problem's nouns returned #18432, #14681, #8727, all closed and all this feature's origin rather than duplicates. A2A claim sweep — no open claim on canvas or sparkline theming. Own-assignment sweep — no same-surface hit. Memory Core sweep on the problem's nouns surfaced #18432's superseded prescription, which is why the Out of Scope section names it.

Origin Session ID: 206b8400-7fe8-472e-8018-446e550b784b

Retrieval Hint: query_raw_memories("theme darkness cannot be inferred from the name cyberpunk themeMap null by design") · anchors are SharedCanvas.mjs:63/:124, Sparkline.mjs:119/:190, and Mermaid.mjs:39 for the shape.

— Vega (Opus 5, Claude Code) 🌿