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

es6-promise overwrites zone.js #891

Closed
josephliccini opened this issue Sep 1, 2017 · 29 comments · Fixed by #916
Closed

es6-promise overwrites zone.js #891

josephliccini opened this issue Sep 1, 2017 · 29 comments · Fixed by #916

Comments

@josephliccini
Copy link

josephliccini commented Sep 1, 2017

I am not sure exactly which library is exactly responsible for the issue, but if one looks at this line:

https://github.com/stefanpenner/es6-promise/blob/a5838bd94a76e31ad80ac1685bcd0dbc3d8ce963/dist/es6-promise.js#L1133-L1144

One can see that they are expecting
Object.prototype.toString.call(window.Promise.resolve()) to be [object Promise], but zone.js gives [object Object]

So, I am wondering, should es6-promise (coming from another widget hosted on our page served over their CDN) look for [object Object], or should zone.js have [object Promise] for this toString()

@josephliccini
Copy link
Author

josephliccini commented Sep 1, 2017

This seems to work, though not clean:

var oldToString = Object.prototype.toString;
Object.prototype.toString = function () {
    if (this instanceof Promise) {
        return '[object Promise]';
    }
    return oldToString.call(this);
};

Maybe this could be added to zone.js so other polyfills won't overwrite?

@josephliccini
Copy link
Author

Or perhaps Zone.js could make window.Promise a setter function, and anytime it is set, Zone.js wraps with ZoneAwarePromise? So then if any library were to set window.Promise, it could reject it, wrap it, or at least warn? Just brainstorming here

@JiaLiPassion
Copy link
Collaborator

@josephliccini , it seems duplicate with #499, I will check the behavior later.

@josephliccini
Copy link
Author

josephliccini commented Sep 28, 2017

This one seems fixed, and works great for es6-promise! Thanks!

There is one issue I am seeing, but it's not affecting me but may be good for you to know.

I did a test to see what would happen with core-js Promise.

My code has this now:

import 'zone.js';
import 'core-js/es6/promise';

And before bootstrap I get this error:

Uncaught TypeError: NativePromise.resolve is not a function
    at Object.setNativePromise (zone.js:634)
    at desc.set (zone.js:1028)
    at webpackJsonp.../../../../node_modules/core-js/modules/_redefine.js.module.exports (_redefine.js:19)
    at $export (_export.js:27)
    at Object.../../../../node_modules/core-js/modules/es6.promise.js (es6.promise.js:230)
    at __webpack_require__ (?mockauth=2:61)
    at Object.../../../../node_modules/core-js/es6/promise.js (promise.js:4)
    at __webpack_require__ (?mockauth=2:61)
    at Object../vendor.ts (zone.js:3026)
    at __webpack_require__ (?mockauth=2:61)

@JiaLiPassion
Copy link
Collaborator

@josephliccini , thanks for the information, I will check this error.

JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Sep 28, 2017
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Sep 28, 2017
mhevery pushed a commit that referenced this issue Oct 3, 2017
@josephliccini
Copy link
Author

@JiaLiPassion thanks I am excited to try in next release :)

@kflorian
Copy link

Our app is not working on IE11 due to this issue, using version 0.8.18.
Waiting desperately for a fixed version!

@goyalvarun601
Copy link

any update on this?

@JiaLiPassion
Copy link
Collaborator

@goyalvarun601 , this one have been merged, please wait for the next release.

@goyalvarun601
Copy link

thanks @JiaLiPassion , when is the next release?

@JiaLiPassion
Copy link
Collaborator

@goyalvarun601 , I am not sure, please wait for a while.

@mcterrySep
Copy link

I am also interested in when this is resolved.

@yevhenGuba
Copy link

The same is at my side. What is the approximate date for a new release ?

@JiaLiPassion
Copy link
Collaborator

for now, please update your package.json with

    "zone.js": "https://github.com/angular/zone.js.git"

@jonathanbarton
Copy link

next release? when's that

@goyalvarun601
Copy link

I am still getting the same error using "https://github.com/angular/zone.js.git".

zone.js:634 Uncaught TypeError: NativePromise.resolve is not a function
    at Object.setNativePromise (zone.js:634)

Did it solve anyone else's issue?

@goyalvarun601
Copy link

The zip doesn't have the updated dist/zone.js

@JiaLiPassion
Copy link
Collaborator

@goyalvarun601 , you are right, I used the old version, please use this one.
zone.zip

@goyalvarun601
Copy link

thanks @JiaLiPassion

@goyalvarun601
Copy link

@JiaLiPassion Can you push dist/zone.js to master or another branch? I can use the zip locally but I can't deploy anywhere.

@JiaLiPassion
Copy link
Collaborator

@goyalvarun601 , sure, you can use my branch, https://github.com/JiaLiPassion/zone.js/tree/some-fix

@goyalvarun601
Copy link

@JiaLiPassion The branch doesn't have the updated dist/zone.js

@JiaLiPassion
Copy link
Collaborator

@goyalvarun601 , please use this one, https://github.com/JiaLiPassion/zone.js/tree/issue-891

@goyalvarun601
Copy link

Thank you. This works.

@jdespatis
Copy link

thanks @JiaLiPassion it works also for me
=> any idea when it will be merged in zone.js to have an official new version ?

@JiaLiPassion
Copy link
Collaborator

@jdespatis , it has been merged, but I am not sure when there will be a new version.

@jdespatis
Copy link

nice news @JiaLiPassion , but strangely, if I use your branch in my package.json:
"zone.js": "https://github.com/JiaLiPassion/zone.js.git#issue-891",
all is running well,

but when using zone.js master branch, the problem with NativePromise still exists
my package-lock.json indicates the very last commit on zone.js:
"zone.js": {
"version": "git+https://github.com/angular/zone.js.git#326a07fb9095e4a87ff7561cb45fe1d4917c2174"
}

Maybe I'm doing something wrong, or maybe your branch contains more than the fix committed in zone.js ?

@JiaLiPassion
Copy link
Collaborator

@jdespatis , the content are the same between my branch and master, the reason master not work because dist folder is not updated in master branch, it will only be updated when new version released.

@jdespatis
Copy link

ok thanks for your feedback @JiaLiPassion !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
8 participants