fix(zone.js): patch Response methods returned by fetch#50653
Closed
arturovt wants to merge 1 commit intoangular:mainfrom
Closed
fix(zone.js): patch Response methods returned by fetch#50653arturovt wants to merge 1 commit intoangular:mainfrom
Response methods returned by fetch#50653arturovt wants to merge 1 commit intoangular:mainfrom
Conversation
Contributor
JiaLiPassion
left a comment
There was a problem hiding this comment.
LGTM! Could we add a test case about Response in https://github.com/angular/angular/blob/main/packages/zone.js/test/common/fetch.spec.ts
This commit updates the implementation of the `fetch` patch and additionally patches `Response` methods which return promises. These are `arrayBuffer`, `blob`, `formData`, `json` and `text`. This fixes the issue when zone becomes stable too early before all of the `fetch` tasks complete. Given the following code: ```ts appRef.isStable.subscribe(console.log); fetch(...).then(response => response.json()).then(console.log); ``` The `isStable` observer would log `false, true, false, true`. This was happening because `json()` was returning a native promise (and not a `ZoneAwarePromise`). But calling `then` on the native promise returns a `ZoneAwarePromise` which notifies Angular about the task being scheduled and forces to re-calculate the `isStable` state. Issue: angular#50327
Contributor
jessicajaniuk
pushed a commit
that referenced
this pull request
Jan 31, 2024
This commit updates the implementation of the `fetch` patch and additionally patches `Response` methods which return promises. These are `arrayBuffer`, `blob`, `formData`, `json` and `text`. This fixes the issue when zone becomes stable too early before all of the `fetch` tasks complete. Given the following code: ```ts appRef.isStable.subscribe(console.log); fetch(...).then(response => response.json()).then(console.log); ``` The `isStable` observer would log `false, true, false, true`. This was happening because `json()` was returning a native promise (and not a `ZoneAwarePromise`). But calling `then` on the native promise returns a `ZoneAwarePromise` which notifies Angular about the task being scheduled and forces to re-calculate the `isStable` state. Issue: #50327 PR Close #50653
Contributor
|
This PR was merged into the repository by commit 260d3ed. |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This commit updates the implementation of the
fetchpatch and additionally patchesResponsemethods which return promises. These arearrayBuffer,blob,formData,jsonandtext. This fixes the issue when zone becomes stable too early before all of thefetchtasks complete. Given the following code:The
isStableobserver would logfalse, true, false, true. This was happening becausejson()was returning a native promise (and not aZoneAwarePromise). But callingthenon the native promise returns aZoneAwarePromisewhich notifies Angular about the task being scheduled and forces to re-calculate theisStablestate.Closes: #50327