Skip to content

fix(brain-strip): reactive colorScheme so the graph doesn't paint blank white in the VS Code webview - #38

Merged
Rchari1 merged 1 commit into
local/amicodefrom
rchari/brain-strip-webview-theme
Jul 20, 2026
Merged

Rchari1 merged 1 commit into
local/amicodefrom
rchari/brain-strip-webview-theme

Conversation

@Rchari1

@Rchari1 Rchari1 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Problem

The session brain-strip (the animated graph of a session's tool touches) renders in a nested /brain.html iframe. Users saw it as a blank white box where the graph should be — reported in the amicode dev host.

Root cause: brain-strip.tsx baked colorScheme=${scheme} into the iframe src from a one-time snapshot read at mount. Inside the amicode VS Code webview the theme arrives asynchronously (chat_panel seeds it via ?colorScheme= → app preload → data-color-scheme on documentElement), so at brain-strip mount that attribute is often not set yet. The snapshot falls to its default, parent/child color-schemes mismatch, and — per the component's own comment — the browser paints the transparent iframe opaque white.

Fix

  • Track the scheme reactively (createSignal + the existing MutationObserver now calls setScheme) so the iframe src re-syncs to the real theme instead of a stale mount-time value.
  • On every ready handshake from the brain (initial, and after a scheme-driven iframe reload), clear sent and restore initialFlush so the reloaded brain re-receives the full event history — otherwise a reload comes back empty.

Testing

  • tsgo -b: clean
  • Rebuilt the darwin-arm64 binary (smoke test passed), verified in the amicode dev host — graph paints in both light and dark.

Follow-up

Ships to users via a fork release + opencode.lock.json bump in amicode (same path as #37).

…nk white in the VS Code webview

The session brain-strip renders its graph in a nested /brain.html iframe. Its
src baked colorScheme=${scheme} from a ONE-TIME snapshot read at mount. Inside
the amicode VS Code webview the theme arrives asynchronously (chat_panel seeds
it via ?colorScheme= -> app preload -> data-color-scheme on documentElement),
so at brain-strip mount that attribute is often not set yet. The snapshot then
falls to its default, parent and child color-schemes mismatch, and — per the
code's own comment — the browser paints the transparent iframe OPAQUE WHITE.
That is the blank box users saw where the graph should be.

Fix:
- Track the scheme reactively (createSignal + the existing MutationObserver
  now setScheme) so the iframe src re-syncs to the real theme instead of a
  stale mount-time snapshot.
- On every `ready` handshake from the brain (the initial one AND the one after
  a scheme-driven iframe reload), clear the sent-set and restore initialFlush
  so the reloaded brain re-receives the full event history — otherwise a reload
  would come back empty (every id already marked sent).

typecheck (tsgo -b): clean. Rebuilt the darwin-arm64 binary (smoke test
passed) and verified in the amicode dev host.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Rchari1
Rchari1 merged commit c05d2e3 into local/amicode Jul 20, 2026
0 of 4 checks passed
@Rchari1
Rchari1 deleted the rchari/brain-strip-webview-theme branch July 20, 2026 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant