fix: gracefully degrade when onUploadProgress lacks stream support#822
Open
wotan-allfather wants to merge 3 commits intosindresorhus:mainfrom
Open
fix: gracefully degrade when onUploadProgress lacks stream support#822wotan-allfather wants to merge 3 commits intosindresorhus:mainfrom
wotan-allfather wants to merge 3 commits intosindresorhus:mainfrom
Conversation
When environments don't support request streams (e.g., Safari, iOS WebView), the onUploadProgress callback now silently degrades instead of throwing an error. This allows requests to complete successfully without progress reporting in environments with partial ReadableStream support. Closes sindresorhus#691
Collaborator
|
Do people really want it to fail silently? I was thinking we would still report 100% progress, if there's a simple way to implement it. |
Per @sholladay's feedback: instead of silently degrading, report 100% progress completion after the request finishes in environments where request streams aren't supported (Safari, iOS WebView). This gives users feedback that their upload completed, even when incremental progress tracking isn't available. - Track body size when streams aren't supported - Report { percent: 1, transferredBytes: totalBytes, totalBytes } after fetch completes - Supports Blob, ArrayBuffer, TypedArray, string, URLSearchParams - FormData reports totalBytes: 0 (unknown size)
Owner
|
A couple of things:
|
1. Only emit fallback progress when there's actually a body to upload (skip GET/HEAD requests with no body) 2. Only emit fallback progress when an actual network request was made (not when beforeRequest hook returns a Response early) This fixes the cross-environment behavior mismatch and false progress events noted in the review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When environments don't support request streams (e.g., Safari, iOS WebView), the onUploadProgress callback now silently degrades instead of throwing an error. This allows requests to complete successfully without progress reporting in environments with partial ReadableStream support.
Closes #691