Skip to content

feat: support theme control via postMessage for iframe embedding - #32

Merged
wesm merged 1 commit into
kenn-io:mainfrom
thellert:feature/postmessage-theme
Feb 25, 2026
Merged

feat: support theme control via postMessage for iframe embedding#32
wesm merged 1 commit into
kenn-io:mainfrom
thellert:feature/postmessage-theme

Conversation

@thellert

Copy link
Copy Markdown
Contributor

Summary

Details

When agentsview is embedded as a cross-origin iframe, the host application can now send a theme:set message to switch themes instantly. This avoids the jarring reload previously needed when using the ?theme= URL parameter approach.

The implementation is minimal — a single window.addEventListener("message", ...) in the UIStore constructor. Since this.theme is a $state field, assigning it triggers the existing $effect that updates the DOM class and persists to localStorage.

Protocol

iframe.contentWindow.postMessage({ type: "theme:set", theme: "dark" }, "*");

Only "light" and "dark" are accepted; other values are silently ignored.

Test plan

  • Valid theme:set message changes theme
  • Invalid theme value (e.g. "purple") is ignored
  • Unrelated message types are ignored
  • Full test suite passes (384/384, +3 new)

Add a window message listener to UIStore that accepts
{type: "theme:set", theme: "light"|"dark"} messages, allowing
parent windows to control the theme without reloading the iframe.

This enables seamless theme synchronization when agentsview is
embedded as a cross-origin iframe in host applications.
@roborev-ci

roborev-ci Bot commented Feb 25, 2026

Copy link
Copy Markdown

roborev: Combined Review (9855c77)

Verdict: The code is clean (no Medium, High, or Critical issues were found).


Synthesized from 4 reviews (agents: codex, gemini | types: default, security)

@wesm
wesm merged commit 9a08bf6 into kenn-io:main Feb 25, 2026
6 checks passed
cursor Bot referenced this pull request in diazMelgarejo/periscope Jun 1, 2026
## Summary

- Adds a `postMessage` listener to `UIStore` that accepts `{type:
"theme:set", theme: "light"|"dark"}` messages
- Enables parent windows to control agentsview's theme without reloading
the iframe
- Closes #31

## Details

When agentsview is embedded as a cross-origin iframe, the host
application can now send a `theme:set` message to switch themes
instantly. This avoids the jarring reload previously needed when using
the `?theme=` URL parameter approach.

The implementation is minimal — a single
`window.addEventListener("message", ...)` in the UIStore constructor.
Since `this.theme` is a `$state` field, assigning it triggers the
existing `$effect` that updates the DOM class and persists to
localStorage.

## Protocol

```js
iframe.contentWindow.postMessage({ type: "theme:set", theme: "dark" }, "*");
```

Only `"light"` and `"dark"` are accepted; other values are silently
ignored.

## Test plan

- [x] Valid `theme:set` message changes theme
- [x] Invalid theme value (e.g. "purple") is ignored
- [x] Unrelated message types are ignored
- [x] Full test suite passes (384/384, +3 new)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Support theme control via postMessage for iframe embedding

2 participants