Skip to content

fix(safe): desktop preload no longer bundles Effect so the bridge loads - #7

Merged
paulsenon-r merged 1 commit into
mainfrom
safe/preload-bridge-fix
Oct 27, 2026
Merged

paulsenon-r merged 1 commit into
mainfrom
safe/preload-bridge-fix

Conversation

@paulsenon-r

Copy link
Copy Markdown
Collaborator

Problem

Packaged desktop app (safe.0–safe.2) opens to `PrimaryEnvironmentProtocolUnsupportedError`. `preload.ts` imported `managedPolicy`, which bundled Effect (1.2 MB) into `preload.cjs`. Effect's top-level `const setImmediate` collides with Electron's sandboxed-preload wrapper → SyntaxError → `window.desktopBridge` never exposed → renderer falls back to `t3safe://app`.

Fix

  • `preload.ts` reads the build-time `T3CODE_MANAGED_POLICY` define directly (null = allowed, same as `allowsManagedCapability`). Bundle: 1.2 MB → 32 KB, no Effect.
  • `verify-preload-bundle.mjs` now runs the bundle in an Electron-like wrapper (catches duplicate `setImmediate`), requires the Clerk global only when the policy allows t3Connect, and runs at the end of the desktop build.
  • 3 new tests for the gate; baselines + CHANGELOG refreshed.

Verified

Stand-in Electron 44 harness (sandbox, privileged scheme): old preload → bridge `undefined`; new → `object`. Gate fails on old bundle, passes on new. Targeted tests, typecheck, lint, fmt, egress/dependency scans pass.

Not verified

Real DMG launch; artifact-host ledger (CI). Real-Electron smoke in CI is a follow-up.

🤖 Generated with Claude Code

The preload imported `managedPolicy` from @t3tools/shared, which pulled
Effect (1.2 MB) into preload.cjs. Effect's top-level `const setImmediate`
collides with the binding Electron's sandboxed-preload wrapper already
declares, so the whole preload threw a SyntaxError, window.desktopBridge was
never exposed and the app reported PrimaryEnvironmentProtocolUnsupportedError.

The preload now reads the vite-injected __T3CODE_MANAGED_POLICY__ constant
directly (null policy still allows everything); the bundle drops to ~32 KB
with no Effect. verify-preload-bundle now runs the bundle inside an
Electron-like function wrapper so duplicate declarations throw, only requires
the clerk passkeys global when the baked policy allows t3Connect, and runs as
part of the desktop `build` task so the release path cannot ship a dead bridge.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@paulsenon-r
paulsenon-r merged commit e51d2e5 into main Oct 27, 2026
3 checks passed
@paulsenon-r
paulsenon-r deleted the safe/preload-bridge-fix branch October 27, 2026 04:55
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