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

fix(promise): can set native promise after loading zone.js #899

Merged
merged 2 commits into from
Sep 15, 2017

Conversation

JiaLiPassion
Copy link
Collaborator

fix #898, #891, #783

currently after loading zone.js, if we load some libraries which will override global Promise, Zone.assertZonePatched will throw error, and angular will not started.
Sometimes we use 3rd party libraries and hard to control the load orders. So we need a better way to handle this process.

in this PR.

  1. patch global.Promise with a setter by using Object.defineProperty , so after loading zone.js, if a new Promise want to override global.Promise, it will not update the global.Promise, but update the underlying NativePromise, so the whole process will be:

    • before loading zone.js, NativePromise is Browser built in Promise.
    • load zone.js, global.Promise is ZoneAwarePromise, global[symbolPromise] is NativePromise.
    • after loading zone.js, set other Promise, such as es6-promise, global.Promise is still ZoneAwarePromise, and global[symbolPromise] will be updated to es6-promise.
  2. Zone.assertZonePatched will only throw error when user set this before loading zone.js

__Zone_disable_Promise = true;

@mhevery
Copy link
Contributor

mhevery commented Sep 13, 2017

This looks like a good idea. Let me know when it is ready.

@JiaLiPassion
Copy link
Collaborator Author

JiaLiPassion commented Sep 13, 2017

@mhevery , I have resolved the conflict and rebased, please review.

And I also disable safari 9.3 jasmine test on ios 9, because in saucelabs + jasmine, recently it is very slow on ios9 and will timeout on several cases, but in mocha it is ok, so ios9 will still be tested. And I will continue to tuning the ios9 jasmine cases.

@josephliccini
Copy link

josephliccini commented Sep 14, 2017

This is great and will alleviate a huge pain for us. We have to load a variety of widgets from CDN built by different teams that all serve all sorts of Promise polyfills. Thank you for the fix! Looking forward to the next release of zone.js with this fixed

@Mystic-Ervo
Copy link

Looks like the error has returned, I can't execute my angular universal server-side app, node throws me that error when I try it.
This error has been fixed in multiple times and always return, looks like a nightmare!

(node:15488) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
/var/www/html/proyectoclase/server.js:3024
 */!function(e){var t=e.performance;functionn(e){t&&t.mark&&t.mark(e)}function r(e,n){t&&t.measure&&t.measure(e,n)}if(n("Zone"),e.Zone)throw new Error("Zone already loaded.");var i,o=function(){function t(e,t){this._properties=null,this._parent=e,this._name=t?t.name||"unnamed":"<root>",this._properties=t&&t.properties||{},this._zoneDelegate=new s(this,this._parent&&this._parent._zoneDelegate,t)}return t.assertZonePatched=function(){if(e.Promise!==k.ZoneAwarePromise)throw new Error("Zone.js has detected that ZoneAwarePromise `(window|global).Promise` has been overwritten.\nMost likely cause is that a Promise polyfill has been loaded after Zone.js (Polyfilling Promise api is not necessary when zone.js is loaded. If you must load one, do so before loading zone.js.)")},Object.defineProperty(t,"root",{get:function(){for(var e=t.current;e.parent;)e=e.parent;return e},enumerable:!0,configurable:!0}),Object.defineProperty(t,"current",{get:function(){return O.zone},enumera

Error: listen EACCES http://https://wikos-inc.com/proyectoclase/
        at Server.setupListenHandle [as _listen2] (net.js:1313:19)
        at listenInCluster (net.js:1378:12)
        at Server.listen (net.js:1477:5)
        at Function._.listen (/var/www/html/proyectoclase/server.js:2900:4545)
        at Object.<anonymous> (/var/www/html/proyectoclase/server.js:3077:2865)
        at n (/var/www/html/proyectoclase/server.js:1:172)
        at /var/www/html/proyectoclase/server.js:1:979
        at Object.<anonymous> (/var/www/html/proyectoclase/server.js:1:990)
        at Module._compile (internal/modules/cjs/loader.js:702:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
Emitted 'error' event at:
        at emitErrorNT (net.js:1357:8)
        at e.invokeTask (/var/www/html/proyectoclase/server.js:3024:7685)
        at t.runTask (/var/www/html/proyectoclase/server.js:3024:2865)
        at t.invokeTask (/var/www/html/proyectoclase/server.js:3024:8799)
        at o.useG.invoke (/var/www/html/proyectoclase/server.js:3024:8690)
        at t.args.(anonymous function) (/var/www/html/proyectoclase/server.js:3077:831)
        at process._tickCallback (internal/process/next_tick.js:63:19)
        at Function.Module.runMain (internal/modules/cjs/loader.js:746:11)
        at startup (internal/bootstrap/node.js:238:19)
        at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)

@JiaLiPassion
Copy link
Collaborator Author

@Mystic-Ervo , some how the zone.js was imported twice, this has been fixed here , #1093, please wait for the next release.

@Mystic-Ervo
Copy link

@JiaLiPassion oh, nice! ^^
Thanks for answering!

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.

Error because of a conflict with Google Tag Manager code
5 participants