Skip to content

Page loading issue with Angular 2 #303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
brian428 opened this issue Jun 1, 2016 · 8 comments
Closed

Page loading issue with Angular 2 #303

brian428 opened this issue Jun 1, 2016 · 8 comments
Labels

Comments

@brian428
Copy link

brian428 commented Jun 1, 2016

I've got an Angular 2 app (based on https://github.com./mgechev/angular2-seed). Testing in the latest Chrome release. Everything is working fine until I include the jszip (or jszip.min) script. When I load the page with jszip included, rendering of the whole app just stops. If I take jszip back out, everything works again. I'm not even doing anything with JSZip yet. Simply loading the library triggers this.

Unfortunately, there are no errors thrown, so I really have no idea what the problem is. So I don't have a lot of information to provide on this, but I thought I'd add an issue in case this rings any bells with the folks running the project. I'm not sure why jszip (which I would assume has no UI interaction built into it all) would cause a problem (and a "silent" problem at that) with application loading. If anyone has any ideas, I'm all ears.

If I can, I'll try to replicate it in a more basic app.

@brian428
Copy link
Author

brian428 commented Jun 1, 2016

I think I got things working by changing the timing of the script load. Loading it earlier (before some of the other scripts) seems to help. Still not sure why that would matter, but for now I'll go ahead and close this. Thanks.

@brian428 brian428 closed this as completed Jun 1, 2016
@dduponchel
Copy link
Contributor

That shouldn't happen. Did you reproduce this issue with a basic app ?

@natcohen
Copy link

Got the same problem, this issue should be re-opened.

It seems that the page loading problem appears when JSZip script is called after script(type='text/javascript' src="node_modules/zone.js/dist/zone.js")

@moritz-h
Copy link

Please reopen. I have the same problem. If i include JSZip before zone.js it works, if i include it after zone.js angular stops working.

I tried to figure out where the problem is and guess perhaps it has something to do with promises.
To test i started with the angular quickstart and tutorial and tested step by step when this error starts.
Look here: https://angular.io/docs/ts/latest/tutorial/

Until Step 4. "Multiple Components" everything is fine.
After Step 5. "Services" you can see the error if JSZip is included after zone.js.
I changed the return of the service to directly return the data instead of a promise and there is no error.
So i think this error has anything to do with promises.

@brian428
Copy link
Author

Careful though. Zone does a lot of crazy stuff, so it's certainly possible that the issue is with Zone and not JSZip. However, Zone is being used/beaten on/tested by a lot of people, so one would hope that a problem like this would be noticed if it were indeed with Zone.

@moritz-h
Copy link

I was thinking of a conflict between zone and jszip, so the error could be on both sides. I was thinking of zone and jszip perhaps defining different things to the name "Promise". (I'm far from an javascript expert so i don't know if this thought is helpful)

But i played a little with the jszip source and changed 2 lines here:
https://github.com./Stuk/jszip/blob/master/dist/jszip.js#L289-L296

comment out line 298:
//var ES6Promise = require("es6-promise").Promise;

change line 295:
Promise: ES6Promise
to
Promise: Promise

so i assume Promise must be defined global or before, but with this changes the error is gone, at least for me.
(I know this not looks like a bugfix, but perhaps it can help finding where the bug comes from)

@dduponchel
Copy link
Contributor

but perhaps it can help finding where the bug comes from

@moritz-h you're right !

Zone.js overwrites the global Promise with a ZoneAwarePromise. Then, JSZip calls es6-promise which replace (sometimes) the global Promise (bug #304), breaking everything.

@dduponchel dduponchel reopened this Jul 19, 2016
@dduponchel dduponchel added the bug label Jul 24, 2016
dduponchel added a commit to dduponchel/jszip that referenced this issue Jul 24, 2016
Importing `es6-promise` had a side effect: this library replaces the
global Promise object (Stuk#304) (or tries to, Stuk#309). This is an intended
side effect from this library and while its version 4 should give us a
switch for this behavior, I don't know when it will be out (the master
branch of this project still auto replace the Promise).

I replaced it by `vow` which match the requirements:
- a Promise implementation
- a lightweight one
- works in IE6
- doesn't have too many dependencies

If a global Promise already exists, prefer it: a native promise is
likely to be better integrated anyway (unhandledRejection in node) and
some libraries (zone.js for example) replace global objects (Stuk#303).

I think it is enough for a semver minor version.

Fix Stuk#303 Stuk#304 Stuk#309
@dduponchel
Copy link
Contributor

Fixed in v3.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants