refactor(web-next): move bindAll to root layout

Centralizes DI initialization in the root layout so individual pages
and the tRPC route handler no longer need to import or call it.
This commit is contained in:
danijel-lf
2026-05-26 14:19:00 +02:00
parent d71e30bb3a
commit 15d603b00c
5 changed files with 2 additions and 8 deletions

View File

@@ -2,10 +2,8 @@ import { dehydrate, HydrationBoundary } from "@tanstack/react-query";
import { appRouter } from "@repo/core-api"; import { appRouter } from "@repo/core-api";
import { getQueryClient } from "@repo/core-trpc"; import { getQueryClient } from "@repo/core-trpc";
import { PageContent } from "@repo/marketing-pages/ui"; import { PageContent } from "@repo/marketing-pages/ui";
import { bindAll } from "../../server/bind-production";
export default async function AboutPage() { export default async function AboutPage() {
await bindAll();
const caller = appRouter.createCaller({}); const caller = appRouter.createCaller({});
const queryClient = getQueryClient(); const queryClient = getQueryClient();

View File

@@ -1,9 +1,7 @@
import { fetchRequestHandler } from "@trpc/server/adapters/fetch"; import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
import { appRouter } from "@repo/core-api"; import { appRouter } from "@repo/core-api";
import { bindAll } from "../../../../server/bind-production";
const handler = async (req: Request) => { const handler = async (req: Request) => {
await bindAll();
return fetchRequestHandler({ return fetchRequestHandler({
endpoint: "/api/trpc", endpoint: "/api/trpc",
req, req,

View File

@@ -3,14 +3,12 @@ import { dehydrate, HydrationBoundary } from "@tanstack/react-query";
import { appRouter } from "@repo/core-api"; import { appRouter } from "@repo/core-api";
import { getQueryClient } from "@repo/core-trpc"; import { getQueryClient } from "@repo/core-trpc";
import { ArticleDetail } from "@repo/blog/ui"; import { ArticleDetail } from "@repo/blog/ui";
import { bindAll } from "../../../server/bind-production";
type PageProps = { type PageProps = {
params: Promise<{ slug: string }>; params: Promise<{ slug: string }>;
}; };
export default async function BlogPostPage({ params }: PageProps) { export default async function BlogPostPage({ params }: PageProps) {
await bindAll();
const { slug } = await params; const { slug } = await params;
const caller = appRouter.createCaller({}); const caller = appRouter.createCaller({});
const queryClient = getQueryClient(); const queryClient = getQueryClient();

View File

@@ -1,6 +1,7 @@
import type { Metadata } from "next"; import type { Metadata } from "next";
import "../styles/app.css"; import "../styles/app.css";
import { getNonce } from "@repo/core-shared/security/next"; import { getNonce } from "@repo/core-shared/security/next";
import { bindAll } from "../server/bind-production";
import { Providers } from "./providers"; import { Providers } from "./providers";
export const metadata: Metadata = { export const metadata: Metadata = {
@@ -13,6 +14,7 @@ export default async function RootLayout({
}: { }: {
children: React.ReactNode; children: React.ReactNode;
}) { }) {
await bindAll();
const nonce = await getNonce(); const nonce = await getNonce();
return ( return (

View File

@@ -3,10 +3,8 @@ import { appRouter } from "@repo/core-api";
import { getQueryClient } from "@repo/core-trpc"; import { getQueryClient } from "@repo/core-trpc";
import { SiteHeader } from "@repo/navigation/ui"; import { SiteHeader } from "@repo/navigation/ui";
import { ArticleList } from "@repo/blog/ui"; import { ArticleList } from "@repo/blog/ui";
import { bindAll } from "../server/bind-production";
export default async function Home() { export default async function Home() {
await bindAll();
const caller = appRouter.createCaller({}); const caller = appRouter.createCaller({});
const queryClient = getQueryClient(); const queryClient = getQueryClient();