Skip to content

Commit

Permalink
fix: don't reassign closed-over parameter in fromFetch
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed Jan 15, 2020
1 parent 55fbe58 commit 065a41c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/internal/observable/dom/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export function fromFetch(input: string | Request, init?: RequestInit): Observab
let abortable = true;
let unsubscribed = false;

let perSubscriberInit;
if (init) {
// If a signal is provided, just have it teardown. It's a cancellation token, basically.
if (init.signal) {
Expand All @@ -72,12 +73,14 @@ export function fromFetch(input: string | Request, init?: RequestInit): Observab
init.signal.addEventListener('abort', outerSignalHandler);
}
}
init = { ...init, signal };
// init cannot be mutated or reassigned as it's closed over by the
// subscriber callback and is shared between subscribers.
perSubscriberInit = { ...init, signal };
} else {
init = { signal };
perSubscriberInit = { signal };
}

fetch(input, init).then(response => {
fetch(input, perSubscriberInit).then(response => {
abortable = false;
subscriber.next(response);
subscriber.complete();
Expand Down

0 comments on commit 065a41c

Please sign in to comment.