Skip to content
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

Maximum call stack exceeded when running Dexie with zone.js 0.8.18 #589

Closed
duydao opened this issue Sep 30, 2017 · 8 comments
Closed

Maximum call stack exceeded when running Dexie with zone.js 0.8.18 #589

duydao opened this issue Sep 30, 2017 · 8 comments

Comments

@duydao
Copy link

duydao commented Sep 30, 2017

I'm getting the following error when accessing any database using Ionic 3.7:

dexie.es.js:1382 Unhandled rejection: RangeError: Maximum call stack size exceeded
    at getErrorWithStack (http://localhost:8100/build/vendor.js:120381:27)
    at new Promise (http://localhost:8100/build/vendor.js:120807:29)
    at Promise.then [as __zone_symbol__then] (http://localhost:8100/build/vendor.js:120836:22)
    at r (http://localhost:8100/build/polyfills.js:3:7143)
    at t.scheduleTask (http://localhost:8100/build/polyfills.js:3:14860)
    at r.scheduleTask (http://localhost:8100/build/polyfills.js:3:10785)
    at r.scheduleMicroTask (http://localhost:8100/build/polyfills.js:3:11037)
    at f (http://localhost:8100/build/polyfills.js:3:19578)
    at t.then (http://localhost:8100/build/polyfills.js:3:21934)
    at http://localhost:8100/build/vendor.js:120730:41

The message keeps repeating in the console.

I've tested the following things:

  • The Error does not occur when I'm using the "Getting started" example without typescript
  • It works with ionic 3.6 using Angular 4.5.3 and zone.js 0.8.18

I've reproduced the problem by creating a fork from the ionic conference example app, which be used like this:

git clone https://github.com/duydao/ionic-conference-app.git
npm i
npm run serve
  • open localhost:8100 with chrome when the server is ready
  • call window.dexieService.friends.count().then(console.log).catch(console.error) in the dev console
  • error occures

The dexie implementation can be found in src/pages/schedule/schedule.ts and is as simple as this:

export class DexieService extends Dexie {
  friends: Dexie.Table<any, string>;

  constructor() {
    super('friend_database');
    this.version(1).stores({
      friends: 'name,shoeSize'
    });
  }
}

any hints on how I can debug this error?

@duydao duydao changed the title Maximum call stack exceeded when running Dexie with Ionic 3.7 / 3.7.1 Maximum call stack exceeded when running Dexie with Ionic 3.7.1 Sep 30, 2017
@duydao
Copy link
Author

duydao commented Sep 30, 2017

@duydao duydao changed the title Maximum call stack exceeded when running Dexie with Ionic 3.7.1 Maximum call stack exceeded when running Dexie with zone.js 0.8.18 Sep 30, 2017
@duydao
Copy link
Author

duydao commented Sep 30, 2017

Ionic is using zone.js in a polyfill and ignores the zone.js version defined by package.json. Using dexie with a polyfill that contains zone.js 0.8.17 works, but dexie will fail when using zone.js 0.8.18

@duydao
Copy link
Author

duydao commented Sep 30, 2017

May be related to angular/zone.js#899

@duydao
Copy link
Author

duydao commented Oct 1, 2017

This line is problematic since zone.js 0.8.18:

https://github.com/dfahlander/Dexie.js/blob/407fbca11103ac204739649ebe7fdf75f618bb7e/src/Promise.js#L747

Removing the line works for me, but I guess that will have side effects. Any chance someone with more knowledge could look into this?

@dfahlander
Copy link
Collaborator

dfahlander commented Oct 1, 2017

Thanks for notifying about this change in zone.js. I read about the threads you linked to and the changes in zone 0.8.18.

The direct impact of removing that line, is that indexedDB transactions break on some browsers. However, on most modern browsers today (Edge, Safari >=10.1, Chromium, but not Firefox or IE), it will work just fine, as they have made their IndexedDB API Promise compatible within transactions (see #317).

My suggestion would be that we should replace the property rather than calling the setter. I assume zone.js leaves the "Promise" property configurable. If so, we should replace/restore the property rather than just set window.Promise. This would probably fix the issue.

I just made a pull request #590 that does this. @duydao Could you test it for me?

In regards to the state of modern browsers today (except Firefox), I might also consider feature-testing whether replacing window.Promise is needed or not and leave out the line for browsers that already has a healthy relationship between their IndexedDB and Promise implementations.

@dfahlander
Copy link
Collaborator

As a side note: we're not dribbling out zonejs here, even though it might seem so. When Dexie.Promise needs to schedule a micro task, it does that by invoking the unchanged global Promise' prototype.then(), which is a zonejs controlled Promise implementation. And any macro tasks are only invoked by indexedDB events, which are also controlled by zonejs.

@dfahlander
Copy link
Collaborator

Thanks a lot @duydao for doing the hard work and boiling down the issue to the line that causes it! Also for testing out the fix. I'll release a version 2.0.1 with this and a solution for the issue with PR #579.

@dfahlander
Copy link
Collaborator

Closing this as it is solved in master branch.

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

No branches or pull requests

2 participants