Skip to content

Replace per-class toMessage() overrides with a single spread in GenericEvent - #12

Open
afreakk wants to merge 1 commit into
wxt-and-manifest-v3from
claude/review-feature-branches-3fylyp
Open

Replace per-class toMessage() overrides with a single spread in GenericEvent#12
afreakk wants to merge 1 commit into
wxt-and-manifest-v3from
claude/review-feature-branches-3fylyp

Conversation

@afreakk

@afreakk afreakk commented Jul 10, 2026

Copy link
Copy Markdown
Owner

What

Removes ~120 lines of hand-written serialization boilerplate from the event/message classes. Every subclass of GenericEvent overrode toMessage() just to re-list its own fields; the base class now does it once with an object spread:

toMessage() {
    return { ...this };
}

All 12 subclass overrides are deleted (eventMessage.ts, SetSceneEvent, SetSceneSettingsEvent, SettingsWindowEvent). Adding a field to an event class no longer requires remembering to also add it to toMessage().

Why this is behavior-preserving

  • All event fields are enumerable own properties, so { ...this } produces the same message object; methods live on the prototype and are not copied.
  • InitiateStreamEvent and SettingsWindowEvent previously omitted an undefined source key; the spread keeps it as source: undefined. No receiver distinguishes the two — every reader uses .source with ??/ternary fallbacks (offscreenWindow/main.ts:128, background.ts:140, sandbox/main.ts:113), and chrome.runtime.sendMessage drops undefined values during JSON serialization anyway.

Verification

  • pnpm run compile (tsc) and pnpm run lint (biome) pass.
  • Playwright e2e suite: 29/30 passed. The single failure ("FPS emission requires a valid message source") also fails on the unmodified base branch in the same environment (which additionally flaked on one capture-source test, 28/30) — pre-existing flakiness, unrelated to this change.

No overlap with drop-sandbox-iframe-butterchurn3 — that branch doesn't touch these files.

🤖 Generated with Claude Code

https://claude.ai/code/session_0152TXW9J4VcAkvuNYn6hYBh


Generated by Claude Code

…icEvent

Every event subclass hand-wrote a toMessage() that re-listed its own
fields. Since all fields are enumerable own properties, a single
{ ...this } in the GenericEvent base produces the same message object;
methods live on the prototype and are not copied.

The conditional undefined-field omission in InitiateStreamEvent and
SettingsWindowEvent is dropped: no receiver distinguishes an absent key
from an undefined value (all use ?? / ternary fallbacks), and
chrome.runtime.sendMessage drops undefined values during JSON
serialization anyway.

Verified: tsc --noEmit and biome pass; Playwright e2e suite 29/30
passed (the one failure, "FPS emission requires a valid message
source", also fails on the unmodified base in this environment and is
unrelated).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0152TXW9J4VcAkvuNYn6hYBh
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.

2 participants