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.

fix(core): Return fetch source cancellation to old behaviour (#3239)

authored by

Phil Pluckthun and committed by
GitHub
c2646cf2 236f018f

+14 -9
+5
.changeset/famous-snakes-double.md
··· 1 + --- 2 + '@urql/core': patch 3 + --- 4 + 5 + Return `AbortController` invocation to previous behaviour where it used to be more forceful. It will now properly abort outside of when our generator yields results, and hence now also cancels requests again that have already delivered headers but are currently awaiting a response body.
+9 -9
packages/core/src/internal/fetchSource.ts
··· 1 - import { Source, fromAsyncIterable, filter, pipe } from 'wonka'; 1 + import { Source, fromAsyncIterable, onEnd, filter, pipe } from 'wonka'; 2 2 import { Operation, OperationResult, ExecutionResult } from '../types'; 3 3 import { makeResult, makeErrorResult, mergeResultPatch } from '../utils'; 4 4 ··· 108 108 fetchOptions: RequestInit 109 109 ) { 110 110 let networkMode = true; 111 - let abortController: AbortController | void; 112 111 let result: OperationResult | null = null; 113 112 let response: Response | void; 114 113 115 114 try { 116 - if (typeof AbortController !== 'undefined') { 117 - fetchOptions.signal = (abortController = new AbortController()).signal; 118 - } 119 - 120 115 // Delay for a tick to give the Client a chance to cancel the request 121 116 // if a teardown comes in immediately 122 117 yield await Promise.resolve(); ··· 161 156 : error, 162 157 response 163 158 ); 164 - } finally { 165 - if (abortController) abortController.abort(); 166 159 } 167 160 } 168 161 ··· 198 191 url: string, 199 192 fetchOptions: RequestInit 200 193 ): Source<OperationResult> { 194 + let abortController: AbortController | void; 195 + if (typeof AbortController !== 'undefined') { 196 + fetchOptions.signal = (abortController = new AbortController()).signal; 197 + } 201 198 return pipe( 202 199 fromAsyncIterable(fetchOperation(operation, url, fetchOptions)), 203 - filter((result): result is OperationResult => !!result) 200 + filter((result): result is OperationResult => !!result), 201 + onEnd(() => { 202 + if (abortController) abortController.abort(); 203 + }) 204 204 ); 205 205 }