-
Notifications
You must be signed in to change notification settings - Fork 897
fix(desktop): separate env files by context to prevent renderer crashes #421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fbca395
fix(desktop): fix env var handling to prevent renderer crashes
saddlepaddle 15069a3
ci(desktop): use production env for PostHog keys
saddlepaddle 6d9a936
refactor(desktop): split env.ts into main/renderer variants
saddlepaddle 421ec41
refactor(desktop): rename env files for clarity and add shared env
saddlepaddle 1d6043f
refactor(desktop): use env.shared.ts in shared code for consistency
saddlepaddle 9c627aa
chore(desktop): fix lint issues
saddlepaddle a1eba49
fix(desktop): address PR feedback
saddlepaddle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /** | ||
| * Environment variables for the RENDERER PROCESS (browser context). | ||
| * | ||
| * These values are injected at BUILD TIME by Vite's `define` in electron.vite.config.ts. | ||
| * They are NOT read from process.env at runtime - Vite replaces the references with | ||
| * literal strings during compilation. | ||
| * | ||
| * Only import this file in src/renderer/ code - never in main or shared code. | ||
| * | ||
| * For main process env vars, use src/main/env.main.ts instead. | ||
| */ | ||
| import { z } from "zod/v4"; | ||
|
|
||
| const envSchema = z.object({ | ||
| NODE_ENV: z | ||
| .enum(["development", "production", "test"]) | ||
| .default("development"), | ||
| NEXT_PUBLIC_API_URL: z.url().default("https://api.superset.sh"), | ||
| NEXT_PUBLIC_WEB_URL: z.url().default("https://app.superset.sh"), | ||
| NEXT_PUBLIC_POSTHOG_KEY: z.string().optional(), | ||
| NEXT_PUBLIC_POSTHOG_HOST: z.string().default("https://us.i.posthog.com"), | ||
| }); | ||
|
|
||
| /** | ||
| * Build-time environment variables. | ||
| * | ||
| * Vite replaces these process.env.* and import.meta.env.* references at build time. | ||
| * The values are baked into the bundle as string literals. | ||
| */ | ||
| const rawEnv = { | ||
| // These are replaced by Vite's define at build time | ||
| NODE_ENV: process.env.NODE_ENV, | ||
| NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL, | ||
| NEXT_PUBLIC_WEB_URL: process.env.NEXT_PUBLIC_WEB_URL, | ||
| NEXT_PUBLIC_POSTHOG_KEY: import.meta.env.NEXT_PUBLIC_POSTHOG_KEY as | ||
| | string | ||
| | undefined, | ||
| NEXT_PUBLIC_POSTHOG_HOST: import.meta.env.NEXT_PUBLIC_POSTHOG_HOST as | ||
| | string | ||
| | undefined, | ||
| }; | ||
|
|
||
| export const env = envSchema.parse(rawEnv); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /** | ||
| * Environment variables safe for SHARED CODE (main + renderer). | ||
| * | ||
| * This file only accesses individual process.env properties that are: | ||
| * 1. Defined in Vite's `define` block (replaced at build time for renderer) | ||
| * 2. Available in main process via actual process.env | ||
| * | ||
| * DO NOT spread ...process.env here - that only works in main process. | ||
| * | ||
| * For main-process-only env vars (API URLs, etc.), use src/main/env.main.ts | ||
| * For renderer-only env vars (PostHog, etc.), use src/renderer/env.renderer.ts | ||
| */ | ||
| import { z } from "zod/v4"; | ||
|
|
||
| const envSchema = z.object({ | ||
| NODE_ENV: z | ||
| .enum(["development", "production", "test"]) | ||
| .default("development"), | ||
| }); | ||
|
|
||
| /** | ||
| * Shared environment variables. | ||
| * | ||
| * These work in both main and renderer because Vite's `define` replaces | ||
| * process.env.NODE_ENV at build time for renderer, while main process | ||
| * reads the actual value at runtime. | ||
| */ | ||
| export const env = envSchema.parse({ | ||
| NODE_ENV: process.env.NODE_ENV, | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.