openreader/src/lib/server/runtime-config-rsc.ts
Richard R ca4228970b fix(server): enforce server-only usage for runtime config resolvers
Add explicit runtime checks to prevent runtime config functions from being called on the client. This guards against accidental client-side invocation by throwing errors if executed outside the server environment.
2026-05-14 13:07:43 -06:00

14 lines
555 B
TypeScript

import { cache } from 'react';
import { getResolvedRuntimeConfig } from '@/lib/server/runtime-config';
/**
* Per-request cached runtime config accessor for React Server Components.
* This avoids duplicate DB/runtime-config reads when multiple RSC layers
* (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();
});