fix(desktop): separate env files by context to prevent renderer crashes

Merged
SA
1y ago
+108-19

Summary

  • Fixed blank screen issue in production builds caused by ...process.env spread being bundled into renderer code
  • Split env.ts into context-specific files:
    • src/main/env.main.ts - Main process env vars (can use t3-env with ...process.env)
    • src/renderer/env.renderer.ts - Renderer env vars (uses Zod with Vite-injected values)
    • src/shared/env.shared.ts - Shared env vars (only NODE_ENV, works in both contexts)
  • Updated CI workflow to pass PostHog env vars at build time

Why this works

Vite can only replace individual process.env.X property accesses at build time. The spread ...process.env requires an actual object at runtime, which doesn't exist in the browser. By splitting the env files:

  1. Main process uses t3-env with runtime process.env (Node.js has this)
  2. Renderer uses Zod validation on build-time injected values (Vite define block)
  3. Shared code imports from env.shared.ts which only accesses process.env.NODE_ENV (replaced by Vite)

Test plan

  • Verified typecheck passes
  • Tested deep links work in production build
  • Verified PostHog initializes with key from CI secrets
  • Confirmed app doesn't crash on launch

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Configured production environment settings and analytics tracking integration for the desktop application.
    • Updated environment variable configuration to support customizable API and web service URLs.
    • Reorganized internal environment configuration management for improved application stability.

✏️ Tip: You can customize this high-level summary in your review settings.