diff --git a/src/lib/server/runtime-config-rsc.ts b/src/lib/server/runtime-config-rsc.ts index 74b65a2..da7647f 100644 --- a/src/lib/server/runtime-config-rsc.ts +++ b/src/lib/server/runtime-config-rsc.ts @@ -1,4 +1,3 @@ -import 'server-only'; import { cache } from 'react'; import { getResolvedRuntimeConfig } from '@/lib/server/runtime-config'; @@ -8,6 +7,8 @@ import { getResolvedRuntimeConfig } from '@/lib/server/runtime-config'; * (e.g. layout + page) need the same config in one render. */ export const getResolvedRuntimeConfigForRsc = cache(async () => { + if (typeof window !== 'undefined') { + throw new Error('getResolvedRuntimeConfigForRsc must be called on the server'); + } return getResolvedRuntimeConfig(); }); - diff --git a/src/lib/server/runtime-config.ts b/src/lib/server/runtime-config.ts index 0eb3117..b31eee6 100644 --- a/src/lib/server/runtime-config.ts +++ b/src/lib/server/runtime-config.ts @@ -1,4 +1,3 @@ -import 'server-only'; import { ensureAdminSeed } from '@/lib/server/admin/seed'; import { getRuntimeConfig, @@ -10,12 +9,19 @@ import { export type ResolvedRuntimeConfig = RuntimeConfig; +function assertServerRuntime(caller: string): void { + if (typeof window !== 'undefined') { + throw new Error(`${caller} must be called on the server`); + } +} + /** * Returns the resolved site-wide runtime config in the shape consumed by * the client via SSR injection. Triggers the boot-time seed on first call * so env values land in the DB before the first read. */ export async function getResolvedRuntimeConfig(): Promise { + assertServerRuntime('getResolvedRuntimeConfig'); await ensureAdminSeed(); return getRuntimeConfig(); } @@ -24,6 +30,7 @@ export async function getResolvedRuntimeConfigWithSources(): Promise<{ values: RuntimeConfig; sources: Record; }> { + assertServerRuntime('getResolvedRuntimeConfigWithSources'); await ensureAdminSeed(); return getRuntimeConfigWithSources(); }