From f2c59c56abe7c6df7f2d3c8b8c88ddc5647850f2 Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Mon, 13 Nov 2023 12:17:51 +0100 Subject: [PATCH] fix(react): prioritise context.suspense (#3427) --- .changeset/real-geese-grow.md | 6 ++++++ packages/preact-urql/src/hooks/useQuery.ts | 4 +++- packages/react-urql/src/hooks/useQuery.ts | 4 +++- 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 .changeset/real-geese-grow.md diff --git a/.changeset/real-geese-grow.md b/.changeset/real-geese-grow.md new file mode 100644 index 0000000000..ad4338734d --- /dev/null +++ b/.changeset/real-geese-grow.md @@ -0,0 +1,6 @@ +--- +'urql': patch +'@urql/preact': patch +--- + +Prioritise `context.suspense` and fallback to checking `client.suspense` diff --git a/packages/preact-urql/src/hooks/useQuery.ts b/packages/preact-urql/src/hooks/useQuery.ts index f30e97dde6..cf3c4f9e3e 100644 --- a/packages/preact-urql/src/hooks/useQuery.ts +++ b/packages/preact-urql/src/hooks/useQuery.ts @@ -212,7 +212,9 @@ function toSuspenseSource(source: Source): Source { } const isSuspense = (client: Client, context?: Partial) => - client.suspense && (!context || context.suspense !== false); + context && context.suspense !== undefined + ? !!context.suspense + : client.suspense; const sources = new Map>(); diff --git a/packages/react-urql/src/hooks/useQuery.ts b/packages/react-urql/src/hooks/useQuery.ts index 3e839155ff..673e420236 100644 --- a/packages/react-urql/src/hooks/useQuery.ts +++ b/packages/react-urql/src/hooks/useQuery.ts @@ -175,7 +175,9 @@ export type UseQueryResponse< > = [UseQueryState, UseQueryExecute]; const isSuspense = (client: Client, context?: Partial) => - client.suspense && (!context || context.suspense !== false); + context && context.suspense !== undefined + ? !!context.suspense + : client.suspense; /** Hook to run a GraphQL query and get updated GraphQL results. *