Skip to content

fix(desktop): ensure NODE_ENV is set in t3-env runtimeEnv#371

Merged
saddlepaddle merged 1 commit intomainfrom
fix/desktop-env-node-env
Dec 15, 2025
Merged

fix(desktop): ensure NODE_ENV is set in t3-env runtimeEnv#371
saddlepaddle merged 1 commit intomainfrom
fix/desktop-env-node-env

Conversation

@saddlepaddle
Copy link
Copy Markdown
Collaborator

@saddlepaddle saddlepaddle commented Dec 15, 2025

Summary

  • Fix t3-env not receiving the build-time NODE_ENV value
  • Explicitly set NODE_ENV: process.env.NODE_ENV in runtimeEnv so Vite's define can replace it

Root cause

Previous fix added Vite define for process.env.NODE_ENV, but t3-env uses runtimeEnv: process.env which passes the entire object. The spread doesn't trigger Vite's replacement - only direct property access does.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Refined environment variable configuration in desktop app builds to ensure consistent behavior across packaged releases.

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

The previous fix defined process.env.NODE_ENV at build time, but t3-env
reads from the runtimeEnv object which was just `process.env`. By
explicitly setting NODE_ENV in the runtimeEnv object, Vite's define
can replace it with the build-time value.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 15, 2025

Walkthrough

Modified apps/desktop/src/env.ts to change how runtimeEnv is configured by spreading process.env and explicitly setting NODE_ENV from process.env.NODE_ENV. This ensures Vite's build-time variable replacement works correctly in packaged desktop applications.

Changes

Cohort / File(s) Change Summary
Build-time environment variable injection
apps/desktop/src/env.ts
Refactored runtimeEnv configuration to spread process.env and explicitly assign NODE_ENV from process.env.NODE_ENV to enable proper Vite build-time replacement in packaged apps

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5-10 minutes

  • Single file change with straightforward logic modification
  • Verify that explicit NODE_ENV assignment doesn't cause unintended side effects in build outputs
  • Confirm the Vite define behavior comment accurately reflects the intended mechanism

Possibly related PRs

Poem

🐰 A hop through the build-time mist,
Where NODE_ENV could not be missed,
Now spread and set with hoppy care,
Vite's replacement finds it there!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: ensuring NODE_ENV is properly set in t3-env's runtimeEnv configuration.
Description check ✅ Passed The description provides a clear summary and root cause analysis, but lacks several recommended template sections like Related Issues, Type of Change, Testing, and Additional Notes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/desktop-env-node-env

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 086fb08 and b8603c4.

📒 Files selected for processing (1)
  • apps/desktop/src/env.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
apps/desktop/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (apps/desktop/AGENTS.md)

For Electron interprocess communication, ALWAYS use tRPC as defined in src/lib/trpc

Files:

  • apps/desktop/src/env.ts
apps/desktop/**/*.{ts,tsx}

📄 CodeRabbit inference engine (apps/desktop/AGENTS.md)

apps/desktop/**/*.{ts,tsx}: Please use alias as defined in tsconfig.json when possible
Prefer zustand for state management if it makes sense. Do not use effect unless absolutely necessary

Files:

  • apps/desktop/src/env.ts
**/*.{ts,tsx,js,jsx,json}

📄 CodeRabbit inference engine (AGENTS.md)

Use Biome for code formatting and linting, running at root level for speed

Files:

  • apps/desktop/src/env.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Avoid any type and prioritize type safety in TypeScript code

Files:

  • apps/desktop/src/env.ts
🧠 Learnings (3)
📓 Common learnings
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-12T05:45:09.686Z
Learning: Applies to apps/desktop/src/main/index.ts : Load environment variables in apps/desktop/src/main/index.ts with override: true before any imports
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: apps/desktop/AGENTS.md:0-0
Timestamp: 2025-11-24T21:33:13.267Z
Learning: Applies to apps/desktop/**/*.{ts,tsx} : Please use alias as defined in `tsconfig.json` when possible
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-12T05:45:09.686Z
Learning: Applies to apps/desktop/src/renderer/**/*.{ts,tsx,js,jsx} apps/desktop/src/lib/**/*.{ts,tsx,js,jsx} apps/desktop/src/shared/**/*.{ts,tsx,js,tsx} : Never import Node.js modules in renderer process or shared code, only in main process
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: apps/desktop/AGENTS.md:0-0
Timestamp: 2025-11-24T21:33:13.267Z
Learning: Applies to apps/desktop/**/*.test.{ts,tsx,js,jsx} : Tests should be repeatable
📚 Learning: 2025-12-12T05:45:09.686Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-12T05:45:09.686Z
Learning: Applies to apps/desktop/src/main/index.ts : Load environment variables in apps/desktop/src/main/index.ts with override: true before any imports

Applied to files:

  • apps/desktop/src/env.ts
📚 Learning: 2025-11-24T21:33:13.267Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: apps/desktop/AGENTS.md:0-0
Timestamp: 2025-11-24T21:33:13.267Z
Learning: Applies to apps/desktop/**/*.{ts,tsx} : Please use alias as defined in `tsconfig.json` when possible

Applied to files:

  • apps/desktop/src/env.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Deploy Web
  • GitHub Check: Deploy Marketing
  • GitHub Check: Deploy Admin
  • GitHub Check: Deploy API
  • GitHub Check: Deploy Docs
  • GitHub Check: Build
🔇 Additional comments (1)
apps/desktop/src/env.ts (1)

13-17: LGTM! Correct fix for Vite's define plugin behavior.

The change correctly addresses the issue where Vite's define plugin couldn't replace NODE_ENV when using object spread. By explicitly accessing process.env.NODE_ENV after spreading, you ensure:

  1. All environment variables from process.env are preserved via the spread
  2. The explicit property access allows Vite's build-time replacement to work
  3. The explicit assignment overrides whatever was in the spread

The comment clearly explains the rationale, making it easy for future maintainers to understand this pattern.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Dec 15, 2025

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

Service Status
Neon Database (Neon)

Thank you for your contribution! 🎉


Preview resources have been processed for cleanup

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