Skip to content

feat(http): Use the Fetch backend by default - #58212

Merged
thePunderWoman merged 2 commits into
angular:mainfrom
JeanMeche:feat/fetch-default
Feb 26, 2026
Merged

thePunderWoman merged 2 commits into
angular:mainfrom
JeanMeche:feat/fetch-default

Conversation

@JeanMeche

@JeanMeche JeanMeche commented Oct 15, 2024 •

Copy link
Copy Markdown
Member

This commit replaces the HttpXhrBackend with the FetchBackend as the default implementation of the HttpBackend.
This introduces a breaking change a the FetchBackend does not support the report progress for uploads.
The previous behavior (HttpXhrBackend) can be enabled by setting withXhr() in the provideHttpClient() provider function.

This PR includes a migration schematics to keep the behavior of existing apps as is.

DEPRECATION: withFetch is now deprecated, it can be safely removed.
BREAKING CHANGE: Use the HttpXhrBackend with provideHttpClient(withXhr()) if you want to keep supporting upload progress reports.

@pullapprove
pullapprove Bot requested a review from thePunderWoman October 15, 2024 18:08
@JeanMeche JeanMeche added breaking changes area: common/http Issues related to HTTP and HTTP Client detected: deprecation PR contains a commit with a deprecation labels Oct 15, 2024
@ngbot ngbot Bot added this to the Backlog milestone Oct 15, 2024
@angular-robot angular-robot Bot added detected: breaking change PR contains a commit with a breaking change detected: feature PR contains a feature commit area: core Issues related to the framework runtime and removed detected: deprecation PR contains a commit with a deprecation area: common/http Issues related to HTTP and HTTP Client labels Oct 15, 2024
@JeanMeche
JeanMeche requested review from AndrewKushnir and alan-agius4 and removed request for thePunderWoman October 15, 2024 18:08
@ngbot ngbot Bot modified the milestone: Backlog Oct 15, 2024
@JeanMeche JeanMeche added the area: migrations Issues related to `ng update`/`ng generate` migrations label Oct 15, 2024
@JeanMeche
JeanMeche marked this pull request as draft October 15, 2024 18:12
@angular-robot angular-robot Bot added area: core Issues related to the framework runtime and removed area: core Issues related to the framework runtime labels Oct 15, 2024
@JeanMeche JeanMeche added area: common/http Issues related to HTTP and HTTP Client detected: deprecation PR contains a commit with a deprecation labels Oct 15, 2024
@JeanMeche
JeanMeche marked this pull request as ready for review October 15, 2024 18:32
@angular-robot angular-robot Bot added area: core Issues related to the framework runtime and removed area: common/http Issues related to HTTP and HTTP Client area: core Issues related to the framework runtime labels Oct 15, 2024
Comment thread packages/common/http/src/provider.ts Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be meaningful to extend this a bit with information on what this offers, especially its support for upload progress events.

Thinking about it more, do we already document this limitation of fetch for the 'progress' response mode? We should probably make it clear there as well that withXhr is needed to make it work. Does the fetch backend report an error somehow if progress is requested? Is this actually only about upload progress, or also download progress?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chrome is the only browser that supports a stream as a body (since M105), every browser support streaming the response (hence the support for download progress report).

The FetchBackend doesn't throw any error, it won't just report any progress on uploads. Currently the API only has a single reportProgress property for both update & download progress report, I don't think we should log any warning.

I've updated the doc for the reportProgress property to hint a the new limitation with the default implementation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this use case, it's unfortunate that reportProgress is used for both upload and download, which is why I understand that you don't want a warning. However, given it doesn't seem to be possible to use duplex: "half" with Angular's fetch-backend yet (correct me if I'm wrong), I think a warning would still be good if you set reportProgress to true in dev mode, regardless - at least for now.

Not sure what the ratio is of devs using it to report uploads vs. downloads, but from my anecdotal experience, it's usually for uploads.

@JeanMeche JeanMeche added this to the v22 candidates milestone Nov 24, 2025
@JeanMeche
JeanMeche force-pushed the feat/fetch-default branch 2 times, most recently from ed0d097 to 41065de Compare November 24, 2025 09:58
@JeanMeche
JeanMeche force-pushed the feat/fetch-default branch 2 times, most recently from b17f586 to 25b88b5 Compare January 13, 2026 02:57
@JeanMeche
JeanMeche force-pushed the feat/fetch-default branch 2 times, most recently from a32e2e8 to e95bdc1 Compare February 25, 2026 16:04
@JeanMeche
JeanMeche marked this pull request as ready for review February 25, 2026 16:07
@pullapprove
pullapprove Bot requested a review from thePunderWoman February 25, 2026 16:07
@JeanMeche

JeanMeche commented Feb 25, 2026 •

Copy link
Copy Markdown
Member Author

(G3 migration is almost to use withXhr is almost done).

Migration ✅

* Note: The default `HttpBackend` based on fetch, does not support progress report for uploads.
* Set the `HttpXhrBackend` with `withXhr()` if you need this feature.
*/
readonly reportProgress: boolean = false;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a follow-up, we'll probably deprecate that property and split it into reportUploadProgress and reportDownloadProgress with only the former logging an error when the fetchBackend is used.

@JeanMeche
JeanMeche force-pushed the feat/fetch-default branch 3 times, most recently from 253e078 to e8e1aaf Compare February 25, 2026 20:20
@pullapprove
pullapprove Bot requested a review from kirjs February 25, 2026 23:08

@AndrewKushnir AndrewKushnir left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-for: public-api

@JeanMeche JeanMeche added action: global presubmit The PR is in need of a google3 global presubmit and removed state: blocked labels Feb 25, 2026
@JeanMeche

Copy link
Copy Markdown
Member Author

TGP surfaced some testing failures (where tests use a custom XhrFactory to mock requests).

Cleanup in progress.

…mentation

This commit replaces the `XhrHttpBackend` with the `FetchBackend` as the default implementation of the `HttpBackend`.
This introduces a breaking change a the `FetchBackend` does not support the report progress for uploads.

The previous behavior (`HttpXhrBackend`) can be restored by setting `withXhr()` in the `provideHttpClient()` provider function.

DEPRECATED: `withFetch` is now deprecated, it can be safely removed.
BREAKING CHANGE: Use the `HttpXhrBackend` with `provideHttpClient(withXhr)` if you want to keep supporting upload progress reports.
…sing the `HttpXhrBackend` implementation.

Exisiting applications will be migrated to keep using the XHR backend to prevent any breaking changes. `withXhr()` is to the `provideHttpClient` provider function.
@JeanMeche

Copy link
Copy Markdown
Member Author

TGP is Green

@thePunderWoman

Copy link
Copy Markdown
Contributor

This PR was merged into the repository. The changes were merged into the following branches:

@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: common/http Issues related to HTTP and HTTP Client area: core Issues related to the framework runtime area: migrations Issues related to `ng update`/`ng generate` migrations breaking changes detected: breaking change PR contains a commit with a breaking change detected: deprecation PR contains a commit with a deprecation detected: feature PR contains a feature commit target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants