Skip to content

fix(renderer): fall back on the bridge, not on window - #79

Merged
64ix merged 1 commit into
fork-mainfrom
fix/renderer-ipc-bridge-fallback
Aug 5, 2026
Merged

fix(renderer): fall back on the bridge, not on window#79
64ix merged 1 commit into
fork-mainfrom
fix/renderer-ipc-bridge-fallback

Conversation

@64ix

@64ix 64ix commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Description

src/renderer/lib/ipc.ts guarded on typeof window !== 'undefined' and then read
window.electronAPI. Outside Electron — browser-mode tests, Storybook — window exists
while the preload bridge does not, so it took the first branch, left electronAPI
undefined, and the createRPCClient(electronAPI.invoke) call one line below threw while
the module was still evaluating. Anything transitively importing it failed to load at all,
before any test body ran. Guarding on the bridge itself makes the unavailable-channel
errors written just underneath actually reachable.

This is not hypothetical: #75 landed a browser suite that was red from the first commit —
markdown-renderer-security.test.tsx died with Cannot read properties of undefined (reading 'invoke'). Nothing caught it because .github/workflows/fork-ci.yml runs the
node, main-db, migrations and scripts projects, not the browser one, and the author had no
local Chromium.

The suite also needed the ipc stub every other renderer test installs: importing the
markdown renderer transitively constructs the SSH connection store, whose Resources call
RPC from their constructor, and those rejections failed the file even with both assertions
passing.

In packaged Electron the preload bridge is always present, so the new fallback never fires
there.

Related issues

Follow-up to #75.

Testing

  • pnpm run test (repo root) — 398 files, all 9 projects, browser project included.
    Before this change the same command failed with 1 failed | 397 passed.
  • pnpm typecheck — app + release scripts
  • pnpm exec oxlint .
  • pnpm run format
  • pnpm exec vitest run --project browser src/renderer/tests/browser/markdown-renderer-security.test.tsx
    — 2 passed, 0 errors (was: failed to import)

Screenshot/Recording (if applicable)

Not applicable.

Checklist
  • I kept this PR small and focused
  • I ran a self-review before opening this PR
  • I ran the relevant local checks
  • I added or updated tests when behavior changed
  • I only added comments where the logic is not obvious
  • I used Conventional Commits

`ipc.ts` guarded on `typeof window !== 'undefined'` and then read
`window.electronAPI`, so outside Electron — browser-mode tests, Storybook — it took
the first branch and left `electronAPI` undefined. The `createRPCClient` call one line
down then threw while the module was still evaluating, which took down every module
that transitively imports it, at import time, before any test body ran.

That is how #75's browser suite shipped red: `markdown-renderer-security.test.tsx`
failed with `Cannot read properties of undefined (reading 'invoke')` and nothing
noticed, because fork-ci.yml runs node/main-db/migrations/scripts and not the browser
project. Guarding on the bridge itself makes the unavailable-channel errors below
reachable, which is what they were written for.

The suite also needed the ipc stub every other renderer test installs: importing the
markdown renderer constructs the SSH connection store, whose Resources call RPC from
their constructor, and those rejections failed the file even with both assertions
passing.

Full workspace suite now green: 398 files, browser project included.
@64ix
64ix merged commit 7b8de7e into fork-main Aug 5, 2026
1 check passed
@64ix
64ix deleted the fix/renderer-ipc-bridge-fallback branch August 5, 2026 20:46
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