From f0cea9cdfc5267d26e8a8731cea02c81357b6a19 Mon Sep 17 00:00:00 2001 From: Andy Ingram Date: Sun, 6 Oct 2024 21:03:51 +0100 Subject: [PATCH] Allow @defer to work in queries with suspense enabled --- .changeset/shiny-eagles-join.md | 5 +++++ packages/react-urql/src/hooks/useQuery.ts | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .changeset/shiny-eagles-join.md diff --git a/.changeset/shiny-eagles-join.md b/.changeset/shiny-eagles-join.md new file mode 100644 index 0000000000..2e46af4bbe --- /dev/null +++ b/.changeset/shiny-eagles-join.md @@ -0,0 +1,5 @@ +--- +'urql': minor +--- + +Support use of defer with suspense diff --git a/packages/react-urql/src/hooks/useQuery.ts b/packages/react-urql/src/hooks/useQuery.ts index 673e420236..439bbab45c 100644 --- a/packages/react-urql/src/hooks/useQuery.ts +++ b/packages/react-urql/src/hooks/useQuery.ts @@ -263,7 +263,12 @@ export function useQuery< const subscription = pipe( source, - takeWhile(() => (suspense && !resolve) || !result), + takeWhile( + () => + (suspense && !resolve) || + !result || + ('hasNext' in result && result.hasNext) + ), subscribe(_result => { result = _result; if (resolve) resolve(result);