Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

(react) - Fix pause + executeQuery issue in useQuery (#1722)

Fix #1698

authored by

Phil Pluckthun and committed by
GitHub
395788e2 eed49061

+23 -9
+5
.changeset/grumpy-dogs-allow.md
··· 1 + --- 2 + 'urql': patch 3 + --- 4 + 5 + Fix issue with `useQuery`'s `executeQuery` state updates, where some calls wouldn't trigger a source change and start a request when the hook was paused.
+18 -9
packages/react-urql/src/hooks/useQuery.ts
··· 198 198 ...opts, 199 199 }; 200 200 201 - const source = client.executeQuery(request, context); 202 - 203 201 setState(state => { 204 - const snapshot = 205 - context.requestPolicy !== 'network-only' 206 - ? getSnapshot(source, false) 207 - : { fetching: true }; 208 - const nextResult = computeNextState(state[1], snapshot); 209 - return state[1] !== nextResult ? [source, nextResult, state[2]] : state; 202 + const source = suspense 203 + ? pipe( 204 + client.executeQuery(request, context), 205 + onPush(result => { 206 + cache.set(request.key, result); 207 + }) 208 + ) 209 + : client.executeQuery(request, context); 210 + return [source, state[1], state[2]]; 210 211 }); 211 212 }, 212 - [client, request, getSnapshot, args.requestPolicy, args.context] 213 + [ 214 + client, 215 + cache, 216 + request, 217 + suspense, 218 + getSnapshot, 219 + args.requestPolicy, 220 + args.context, 221 + ] 213 222 ); 214 223 215 224 return [currentResult, executeQuery];