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.
14 lines
555 B
TypeScript
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();
|
|
});
|