Skip to content

Commit c19d415

Browse files
fix: cancellable in-flight multipart urql subscriptions (#12567)
* fix: cancel in-flight multipart urql subscriptions at observer unsubscribe * add: changeset
1 parent d264fef commit c19d415

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

.changeset/hot-kangaroos-eat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@apollo/client": patch
3+
---
4+
5+
Fix in-flight multipart urql subscription cancellation

src/utilities/subscriptions/urql/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ export function createFetchMultipartSubscription(
3535
const currentFetch = preferredFetch || maybe(() => fetch) || backupFetch;
3636
const observerNext = observer.next.bind(observer);
3737

38-
currentFetch!(uri, options)
38+
const abortController = new AbortController();
39+
40+
currentFetch!(uri, { ...options, signal: abortController.signal })
3941
.then((response) => {
4042
const ctype = response.headers?.get("content-type");
4143

@@ -51,6 +53,10 @@ export function createFetchMultipartSubscription(
5153
.catch((err: any) => {
5254
handleError(err, observer);
5355
});
56+
57+
return () => {
58+
abortController.abort();
59+
};
5460
});
5561
};
5662
}

0 commit comments

Comments
 (0)