refactor: split feature UI into .server/.client component pairs
Server components (.server.tsx) resolve controllers from DI, prefetch data, and wrap client components in HydrationBoundary. Client components (.client.tsx) use hooks for hydration + background refetch. Barrel exports server components under clean names — consumers never see the server/client split.
This commit is contained in:
27
packages/navigation/src/ui/components/site-header.server.tsx
Normal file
27
packages/navigation/src/ui/components/site-header.server.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
import { dehydrate, HydrationBoundary } from "@tanstack/react-query";
|
||||
import { getQueryClient } from "@repo/core-trpc";
|
||||
import { navigationContainer } from "../../di/container";
|
||||
import { NAVIGATION_SYMBOLS } from "../../di/symbols";
|
||||
import type { IGetHeaderController } from "../../interface-adapters/controllers/get-header.controller";
|
||||
import { SiteHeader as SiteHeaderClient } from "./site-header.client";
|
||||
|
||||
export async function SiteHeader({
|
||||
siteName,
|
||||
siteDescription,
|
||||
}: {
|
||||
siteName: string;
|
||||
siteDescription?: string;
|
||||
}) {
|
||||
const controller = navigationContainer.get<IGetHeaderController>(
|
||||
NAVIGATION_SYMBOLS.IGetHeaderController,
|
||||
);
|
||||
const header = await controller({});
|
||||
const queryClient = getQueryClient();
|
||||
queryClient.setQueryData(["navigation", "header", { input: {} }], header);
|
||||
|
||||
return (
|
||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||
<SiteHeaderClient siteName={siteName} siteDescription={siteDescription} />
|
||||
</HydrationBoundary>
|
||||
);
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
export { headerQuery } from "./query";
|
||||
export { useHeader } from "./hooks/use-header";
|
||||
export { SiteHeader, type SiteHeaderProps } from "./components/site-header";
|
||||
export { SiteHeader } from "./components/site-header.server";
|
||||
|
||||
Reference in New Issue
Block a user