ionic-team / ionic2-app-base

Template for starting Ionic 2 apps, used by the Ionic CLI
220 stars 150 forks source link

question: Order of polyfills.js #126

Open joewoodhouse opened 7 years ago

joewoodhouse commented 7 years ago

The background to this question comes from https://github.com/driftyco/ionic-native/issues/505

Basically it appears there's an issue with how the FileReader API is patched by various agents, namely Zone.js, Ionic Native and the Cordova file plugin itself. The resulting behaviour made events like onloadend and similar not reliably fire from the FileReader. It pointed to a Zone.js related issue.

After a bit of exploring and experimenting I found that by moving the polyfills.js script tag to the top of my index.html, before the cordova.js tag, the issue went away. Presumably this is because polyfills.js contains zone.js in it, and so by this re-ordering somehow the issue is resolved.

It would be good to know if this is a safe thing to do. Presumably there was a reason why the polyfills.js was put after cordova.js originally.

Any information much appreciated.

pdrosos commented 7 years ago

I am also interested in the answer and if this appears to be safe thing to do, it would be great if Ionic's base project could be updated to include it. This issue took me a lot of time and seems fixed now, so it's best to be initially fixed for other people in the base project. Thanks!

mgaert commented 7 years ago

I would know this as well. Thanks!

joewoodhouse commented 7 years ago

Anyone out there?

paulsouche commented 6 years ago

Hi,

I found angular/zone.js/868 and I can't find a way to use @JiaLiPassion cordova patch properly. If anyone can help it would be great.

Thank you

JiaLiPassion commented 6 years ago

@paulsouche , if it is the same issue which https://github.com/angular/zone.js/issues/868 resolved, you could just use the newest version of zone.js.

paulsouche commented 6 years ago

@JiaLiPassion I'm already on zone.js@0.8.18 and as I said, I was trying to use its cordova patch. But my issue is that if cordova.js script is loaded before zone.js one, sometimes (it depends on how cordova plugins are resolved) cordova FileReader is patched by zone.js instead of window FileReader. And as @ionic-native/file is using global FileReader, something is broken. import zone.js cordova patch do not fix things in this case.

BTW I think that cordova FileReader should not be global and we should not have this conversation but @joewoodhouse's workaround is more a hack than something reliable and that's why I'm asking for help of somebody who know more about cordova @ionic-native/file & zone.js than me.

Thank you for the great job anyway