mixpanel / mixpanel-js

Official Mixpanel JavaScript Client Library
https://mixpanel.com/help/reference/javascript
Other
886 stars 312 forks source link

Using mixpanel-browser@2.4.2 causes endless async event for zone.js #315

Open vyacheslavzhabitsky opened 2 years ago

vyacheslavzhabitsky commented 2 years ago

Hello, When I'm using mixpanel-browser@2.4.2 version with Angular framework - it causes the whole app to be always unstable, it means that in zone.js there are some pending macro tasks(any async event) which are endless. It happens only with latest version 2.4.2. Does anyone have the same issue or any idea what it might be? may be this is a part of new feature like polling of some api?

This is issue is not a blocker and I can solve it via running script outside of angular zone but it worth to pay attention.

tdumitrescu commented 2 years ago

I'm not familiar with zone.js but it sounds like your project probably finally got switched to request-batching mode, which was turned on by default for everyone in v2.42.0. The original release which added this code was v2.36.0. In request-batching mode, track() calls are not immediately sent over the network, they're queued up and flushed in batches at a default rate of every 5 seconds (subject to backoff for retries and other conditions). As long as the request-batcher is still running, it will be using setTimeout to schedule network sends. Most relevant code is here: https://github.com/mixpanel/mixpanel-js/blob/d192aefb6d549a267f8fa825bc2e13e5b2c4f9c4/src/request-batcher.js#L77-L85