Skip to content

Commit

Permalink
refactor: ♻️ t3 7.28.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gracefullight committed Mar 2, 2024
1 parent 856b428 commit 84c93ce
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@
"vitest": "*"
},
"ct3aMetadata": {
"initVersion": "7.26.0"
"initVersion": "7.28.0"
}
}
2 changes: 1 addition & 1 deletion apps/web/public/sw.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion apps/web/src/trpc/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,25 @@ import { useState } from "react";
import type { AppRouter } from "~/server/api/root";
import { getUrl, transformer } from "./shared";

const createQueryClient = () => new QueryClient();

let clientQueryClientSingleton: QueryClient | undefined = undefined;
const getQueryClient = () => {
if (typeof window === "undefined") {
// Server: always make a new query client
return createQueryClient();
}
// Browser: use singleton pattern to keep the same query client
return (clientQueryClientSingleton ??= createQueryClient());
};

export const api = createTRPCReact<AppRouter>();

export function TRPCReactProvider(props: {
children: React.ReactNode;
cookies: string;
}) {
const [queryClient] = useState(() => new QueryClient());
const queryClient = getQueryClient();

const [trpcClient] = useState(() =>
api.createClient({
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@
"node": "20"
},
"ct3aMetadata": {
"initVersion": "7.26.0"
"initVersion": "7.28.0"
}
}
13 changes: 7 additions & 6 deletions packages/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ import { PrismaClient } from "@prisma/client";

export * from "@prisma/client";

const globalForPrisma = globalThis as unknown as {
prisma: PrismaClient | undefined;
};

export const db =
globalForPrisma.prisma ??
const createPrismaClient = () =>
new PrismaClient({
log:
process.env.NODE_ENV === "development"
? ["query", "error", "warn"]
: ["error"],
});

const globalForPrisma = globalThis as unknown as {
prisma: ReturnType<typeof createPrismaClient> | undefined;
};

export const db = globalForPrisma.prisma ?? createPrismaClient();

if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = db;

0 comments on commit 84c93ce

Please sign in to comment.