Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fetch): fix stream handling in Safari by fallback to using a stream reader instead of an async iterator; #6584

Merged
merged 43 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
3f2f496
chore(ci): Add release-it script;
DigitalBrainJS Dec 10, 2022
1bfc41b
Merge branch 'chore/release-it' into v1.x
DigitalBrainJS Dec 10, 2022
acaf0f4
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 15, 2022
8a5de86
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 15, 2022
cff9271
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 17, 2022
67afe20
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 19, 2022
dc7b66d
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 22, 2022
716eb59
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 23, 2022
10216bf
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 29, 2022
3b199f4
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Jan 7, 2023
f3d444f
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Jan 19, 2023
077c381
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Jan 26, 2023
f598657
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Jan 31, 2023
7bf5713
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Feb 5, 2023
81a8bd6
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Mar 8, 2023
f8bb158
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Apr 5, 2023
3f1c768
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Apr 18, 2023
a9b0418
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Apr 25, 2023
1a16f4e
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Apr 27, 2023
5e22e2f
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS May 10, 2023
b7c77b0
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Aug 25, 2023
2200038
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Aug 25, 2023
df38e0c
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Aug 26, 2023
878548a
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Aug 26, 2023
7a33bcd
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Aug 28, 2023
5cafdeb
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Sep 13, 2023
f0e6b28
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Sep 26, 2023
98371b0
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Sep 28, 2023
bee6e45
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Oct 4, 2023
c97df04
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Oct 26, 2023
62274b7
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Oct 28, 2023
2496392
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Nov 15, 2023
127f629
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Jan 2, 2024
435bbfa
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Jan 25, 2024
72c888c
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Apr 21, 2024
9f5b47e
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS May 19, 2024
bca3b63
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Aug 3, 2024
6547392
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Aug 17, 2024
09a1d1e
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Aug 17, 2024
d276f09
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Aug 19, 2024
5290e33
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Aug 20, 2024
13911aa
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Aug 31, 2024
81008f9
fix(fetch): fix stream handling in Safari by fallback to using a stre…
DigitalBrainJS Aug 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/adapters/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export default isFetchSupported && (async (config) => {
progressEventReducer(asyncDecorator(onUploadProgress))
);

data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush, encodeText);
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
}
}

Expand Down Expand Up @@ -189,7 +189,7 @@ export default isFetchSupported && (async (config) => {
trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
flush && flush();
unsubscribe && unsubscribe();
}, encodeText),
}),
options
);
}
Expand Down
30 changes: 25 additions & 5 deletions lib/helpers/trackStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,34 @@ export const streamChunk = function* (chunk, chunkSize) {
}
}

export const readBytes = async function* (iterable, chunkSize, encode) {
for await (const chunk of iterable) {
yield* streamChunk(ArrayBuffer.isView(chunk) ? chunk : (await encode(String(chunk))), chunkSize);
export const readBytes = async function* (iterable, chunkSize) {
for await (const chunk of readStream(iterable)) {
yield* streamChunk(chunk, chunkSize);
}
}

export const trackStream = (stream, chunkSize, onProgress, onFinish, encode) => {
const iterator = readBytes(stream, chunkSize, encode);
const readStream = async function* (stream) {
if (stream[Symbol.asyncIterator]) {
yield* stream;
return;
}

const reader = stream.getReader();
try {
for (;;) {
const {done, value} = await reader.read();
if (done) {
break;
}
yield value;
}
} finally {
await reader.cancel();
}
}

export const trackStream = (stream, chunkSize, onProgress, onFinish) => {
const iterator = readBytes(stream, chunkSize);

let bytes = 0;
let done;
Expand Down
Loading