fix(config): extract RSC-compatible runtime config resolver
Move runtime config resolution logic to a new `runtime-config-rsc.ts` module for use in React Server Components. Update public layout and landing page to consume the RSC-specific resolver, improving compatibility and separation of concerns.
This commit is contained in:
parent
522540452c
commit
fb39723089
3 changed files with 17 additions and 4 deletions
|
|
@ -1,9 +1,9 @@
|
||||||
import type { ReactNode } from 'react';
|
import type { ReactNode } from 'react';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { getResolvedRuntimeConfig } from '@/lib/server/runtime-config';
|
import { getResolvedRuntimeConfigForRsc } from '@/lib/server/runtime-config-rsc';
|
||||||
|
|
||||||
export default async function PublicLayout({ children }: { children: ReactNode }) {
|
export default async function PublicLayout({ children }: { children: ReactNode }) {
|
||||||
const runtimeConfig = await getResolvedRuntimeConfig();
|
const runtimeConfig = await getResolvedRuntimeConfigForRsc();
|
||||||
const enableUserSignups = runtimeConfig.enableUserSignups;
|
const enableUserSignups = runtimeConfig.enableUserSignups;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import type { Metadata } from 'next';
|
import type { Metadata } from 'next';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { getResolvedRuntimeConfig } from '@/lib/server/runtime-config';
|
import { getResolvedRuntimeConfigForRsc } from '@/lib/server/runtime-config-rsc';
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: 'Read and Listen to Documents',
|
title: 'Read and Listen to Documents',
|
||||||
|
|
@ -42,7 +42,7 @@ export const metadata: Metadata = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async function LandingPage() {
|
export default async function LandingPage() {
|
||||||
const runtimeConfig = await getResolvedRuntimeConfig();
|
const runtimeConfig = await getResolvedRuntimeConfigForRsc();
|
||||||
const enableUserSignups = runtimeConfig.enableUserSignups;
|
const enableUserSignups = runtimeConfig.enableUserSignups;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
13
src/lib/server/runtime-config-rsc.ts
Normal file
13
src/lib/server/runtime-config-rsc.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
import 'server-only';
|
||||||
|
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 () => {
|
||||||
|
return getResolvedRuntimeConfig();
|
||||||
|
});
|
||||||
|
|
||||||
Loading…
Reference in a new issue