diff --git a/apps/client/src/app/room/[code]/game/[gameId]/game.tsx b/apps/client/src/app/room/[code]/game/[gameId]/game.tsx index fd4049c..0d5292e 100644 --- a/apps/client/src/app/room/[code]/game/[gameId]/game.tsx +++ b/apps/client/src/app/room/[code]/game/[gameId]/game.tsx @@ -174,22 +174,20 @@ export default function Game({ gameInfo, session }: GameProps) {
- - {isMounted ? ( - - ) : null} - + {isMounted ? ( + + ) : null} ); diff --git a/apps/client/src/components/game/face-off.tsx b/apps/client/src/components/game/face-off.tsx index b224249..47892f9 100644 --- a/apps/client/src/components/game/face-off.tsx +++ b/apps/client/src/components/game/face-off.tsx @@ -49,6 +49,7 @@ const FaceOff = ({ setLoading(false); setVoteSubmitted(true); }; + return (
{currQuestionGenerations ? ( diff --git a/apps/client/src/components/game/next-round.tsx b/apps/client/src/components/game/next-round.tsx index 4effa68..dc70ec6 100644 --- a/apps/client/src/components/game/next-round.tsx +++ b/apps/client/src/components/game/next-round.tsx @@ -9,7 +9,11 @@ type NextRoundProps = { const NextRound = ({ nextQueryNum, totalQueries }: NextRoundProps) => { return ( -

+ Round{" "} {nextQueryNum} @@ -37,7 +41,7 @@ const NextRound = ({ nextQueryNum, totalQueries }: NextRoundProps) => { {" "} of {totalQueries} -

+ ); }; diff --git a/apps/client/src/utils/query-provider.tsx b/apps/client/src/utils/query-provider.tsx index d0f3a74..de787f2 100644 --- a/apps/client/src/utils/query-provider.tsx +++ b/apps/client/src/utils/query-provider.tsx @@ -1,14 +1,49 @@ "use client"; -import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; +import { + isServer, + QueryClient, + QueryClientProvider, +} from "@tanstack/react-query"; -const queryClient = new QueryClient(); +function makeQueryClient() { + return new QueryClient({ + defaultOptions: { + queries: { + // With SSR, we usually want to set some default staleTime + // above 0 to avoid refetching immediately on the client + staleTime: 60 * 1000, + }, + }, + }); +} + +let browserQueryClient: QueryClient | undefined = undefined; + +function getQueryClient() { + if (isServer) { + // Server: always make a new query client + return makeQueryClient(); + } else { + // Browser: make a new query client if we don't already have one + // This is very important, so we don't re-make a new client if React + // suspends during the initial render. This may not be needed if we + // have a suspense boundary BELOW the creation of the query client + if (!browserQueryClient) browserQueryClient = makeQueryClient(); + return browserQueryClient; + } +} export default function QueryProvider({ children, }: { children: React.ReactNode; }) { + // NOTE: Avoid useState when initializing the query client if you don't + // have a suspense boundary between this and the code that may + // suspend because React will throw away the client on the initial + // render if it suspends and there is no boundary + const queryClient = getQueryClient(); return ( {children} );