Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Make fetch() zone-aware without triggering extra requests or uncatchable errors.#622

Merged
mhevery merged 9 commits intoangular:masterfrom
MichaelBuerge:zoneify
Feb 7, 2017
Merged

Make fetch() zone-aware without triggering extra requests or uncatchable errors.#622
mhevery merged 9 commits intoangular:masterfrom
MichaelBuerge:zoneify

Conversation

@MichaelBuerge
Copy link
Copy Markdown
Contributor

Previous implementation called fetch() during setup in order to obtain a result promise from it so its constructor could be patched to make it zone-aware.
This had two problems:

  • Calling fetch() would trigger an unwanted (and unnecessary) HTTP-request.
  • Chrome threw an uncatchable error, which means with open dev tools will halt execution and enter the debugger (which is hugely annoying, as it happens on every page load).

This change replaces fetch() with a wrapper function that lazily ensures the result returned by fetch() is zone-aware.

@googlebot
Copy link
Copy Markdown

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

1 similar comment
@googlebot
Copy link
Copy Markdown

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@MichaelBuerge
Copy link
Copy Markdown
Contributor Author

CLA signed.

@googlebot
Copy link
Copy Markdown

CLAs look good, thanks!

1 similar comment
@googlebot
Copy link
Copy Markdown

CLAs look good, thanks!

@googlebot googlebot added cla: yes and removed cla: no labels Feb 1, 2017
@MichaelBuerge
Copy link
Copy Markdown
Contributor Author

MichaelBuerge commented Feb 1, 2017

Addresses #446

@JiaLiPassion
Copy link
Copy Markdown
Collaborator

JiaLiPassion commented Feb 1, 2017

@MichaelBuerge , please read DEVELOPER.md, before commit part, so you can check your commit. Currently it seems your build failed with tslint part.

@MichaelBuerge
Copy link
Copy Markdown
Contributor Author

@JiaLiPassion Apologies for missing the linter. Everything should be fine now (npm run ci goes through).

@JiaLiPassion
Copy link
Copy Markdown
Collaborator

@MichaelBuerge , you are welcome, could you check my review comment? especially whether the first promise is patched or not one.

@MichaelBuerge
Copy link
Copy Markdown
Contributor Author

@JiaLiPassion I can't find your review comment. As of now, the pull request page still says "no reviews". (Am I looking in the wrong place?)

However, guessing from your comment here, your question seems to be whether the first time the patched fetch() function is called its result promise is properly patched.
That is indeed the case, as the constructor's prototype is modified before any caller can get a hold of the returned promise. Also, the fetch tests (in test/common/Promise.spec.ts) would not pass with an unpatched result promise.
Does this address your concern?

Comment thread lib/zone.ts Outdated
const symbolThenPatched = __symbol__('thenPatched');

function patchThen(Ctor) {
let proto = Ctor.prototype;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we should use const here for proto and originalThen

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread lib/zone.ts Outdated
proto[symbolThen] = originalThen;

Ctor.prototype.then = function(onResolve, onReject) {
let wrapped = new ZoneAwarePromise(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

also const here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@JiaLiPassion
Copy link
Copy Markdown
Collaborator

@MichaelBuerge, sorry I forget to push submit review button...

That is indeed the case, as the constructor's prototype is modified before any caller can get a hold of the returned promise. Also, the fetch tests (in test/common/Promise.spec.ts) would not pass with an unpatched result promise.
Does this address your concern?

yeah, you are right! thank you for explaining this, I didn't realize that.

Copy link
Copy Markdown
Collaborator

@JiaLiPassion JiaLiPassion left a comment

Choose a reason for hiding this comment

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

thank you!

@MichaelBuerge
Copy link
Copy Markdown
Contributor Author

My pleasure!
I assume there's a process in place, but if there's anything left do so this gets merged eventually and the associated issue (#446) closed please let me know.

@mhevery mhevery merged commit 6731ad0 into angular:master Feb 7, 2017
@MichaelBuerge
Copy link
Copy Markdown
Contributor Author

Also addresses #476

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants