From 8d9ea00e1d39d12d5ecf3de5e2a49f5b770e9871 Mon Sep 17 00:00:00 2001 From: Fran Zekan Date: Sun, 17 Jul 2022 19:28:45 +0200 Subject: [PATCH] Fix prefetching multiple queries causes only the last one to be passed to page (#3551) --- .changeset/twelve-lemons-smile.md | 5 +++++ packages/blitz-next/src/index-server.ts | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .changeset/twelve-lemons-smile.md diff --git a/.changeset/twelve-lemons-smile.md b/.changeset/twelve-lemons-smile.md new file mode 100644 index 0000000000..3af96b7c96 --- /dev/null +++ b/.changeset/twelve-lemons-smile.md @@ -0,0 +1,5 @@ +--- +"@blitzjs/next": patch +--- + +Fix prefetching multiple queries causes only the last one to be passed to page diff --git a/packages/blitz-next/src/index-server.ts b/packages/blitz-next/src/index-server.ts index 35e00ca2da..71f5f1270c 100644 --- a/packages/blitz-next/src/index-server.ts +++ b/packages/blitz-next/src/index-server.ts @@ -134,7 +134,9 @@ export const setupBlitzServer = ({plugins, onError}: SetupBlitzOptions) => { defaultOptions = {}, infinite = false, ) => { - queryClient = new QueryClient({defaultOptions}) + if (!queryClient) { + queryClient = new QueryClient({defaultOptions}) + } const queryKey = infinite ? getInfiniteQueryKey(fn, input) : getQueryKey(fn, input) await queryClient.prefetchQuery(queryKey, () => fn(input, ctx))