Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

JeanMeche
Copy link
Member

@JeanMeche JeanMeche commented Oct 15, 2024

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 alan-agius4 and AndrewKushnir 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` 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
*/
export function withFetch(): HttpFeature<HttpFeatureKind.Fetch> {
return makeHttpFeature(HttpFeatureKind.Fetch, [
FetchBackend,
{provide: HttpBackend, useExisting: FetchBackend},
]);
}

/**
* Configures the current `HttpClient` instance to make requests using the Xhr API.
Copy link
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
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
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.

@angular-robot angular-robot bot added the area: core Issues related to the framework runtime label Oct 16, 2024
@alan-agius4 alan-agius4 added the target: major This PR is targeted for the next major release label Oct 16, 2024
@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 16, 2024
JeanMeche added a commit to JeanMeche/angular that referenced this pull request Oct 16, 2024
Introduced back in v15 by angular#47502, its usage with fix with angular#55652 for the `FetchBackend` which will become the default `HttpBackend` with angular#58212
devversion pushed a commit that referenced this pull request Oct 17, 2024
Introduced back in v15 by #47502, its usage with fix with #55652 for the `FetchBackend` which will become the default `HttpBackend` with #58212

PR Close #58221
@JeanMeche JeanMeche force-pushed the feat/fetch-default branch from c5180f5 to c5aebda Compare March 5, 2025 19:03
@angular-robot angular-robot bot added the area: common/http Issues related to HTTP and HTTP Client label Mar 5, 2025
@JeanMeche JeanMeche force-pushed the feat/fetch-default branch 2 times, most recently from 63b41e8 to 754e771 Compare March 24, 2025 10:42
…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 JeanMeche force-pushed the feat/fetch-default branch from 56dc6cf to 849e801 Compare April 1, 2025 21:56
@JeanMeche JeanMeche force-pushed the feat/fetch-default branch from 849e801 to e07973a Compare April 1, 2025 22:11
@JeanMeche JeanMeche removed this from the v20 candidates milestone Apr 3, 2025
@ngbot ngbot bot added this to the Backlog milestone Apr 3, 2025
@csvn
Copy link
Contributor

csvn commented Apr 30, 2025

This PR has some synergy with the recently merged keepalive option (#60621), which requires the use of withFetch to work. Is this PR also planned for Angular v20, since it has some breaking changes?

@JeanMeche
Copy link
Member Author

Hi,

We decided to not change the default HttpBackend for v20 but intend to revisit that for v21.

@csvn
Copy link
Contributor

csvn commented Apr 30, 2025

Alright, cool. Thanks for letting me know πŸ‘‹

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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` 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.

6 participants