Skip to content

Commit b506dc7

Browse files
terencechoclaude
andcommitted
fix(studio): guard import.meta.env for non-Vite consumers
manualEditingAvailability.ts unconditionally reads `import.meta.env`. That's a Vite-only extension; in plain ESM hosts (Next.js / Turbopack, Node, jest in some configs) `import.meta` exists but `import.meta.env` is `undefined`. Reading any property off undefined throws at module evaluation time, so the studio fails to load the moment a non-Vite host imports anything from `@hyperframes/studio`. Guard the read so the module is loadable everywhere; outside Vite, every flag falls back to its declared default, preserving Vite behavior. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 80c88c0 commit b506dc7

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

packages/studio/src/components/editor/manualEditingAvailability.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ export function resolveStudioBooleanEnvFlag(
2727
return fallback;
2828
}
2929

30-
const env = import.meta.env as StudioFeatureFlagEnv;
30+
// Guard `import.meta.env` for non-Vite consumers. The studio is consumable
31+
// from Next.js demos (e.g. hyperframes-internal/demo-next) and other ESM
32+
// hosts where `import.meta` exists but `import.meta.env` is undefined —
33+
// reading any property off `undefined` would crash at module evaluation
34+
// time. In non-Vite hosts every flag falls back to its declared default,
35+
// matching prior intent. Vite consumers are unaffected.
36+
const env = ((typeof import.meta !== "undefined"
37+
? (import.meta as { env?: unknown }).env
38+
: undefined) ?? {}) as StudioFeatureFlagEnv;
3139

3240
export const STUDIO_PREVIEW_MANUAL_EDITING_ENABLED = resolveStudioBooleanEnvFlag(
3341
env,

0 commit comments

Comments
 (0)