mixpanel / mixpanel-js

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

Maximum callstack exceeded #318

Open sara-jegorova opened 2 years ago

sara-jegorova commented 2 years ago

There seems to be a problem with the truncate function in https://github.com/mixpanel/mixpanel-js/blob/master/dist/mixpanel.cjs.js#L421, where it gets stuck on an infinite loop. I found the issue via our runtime error logs, and it seems to happen only to samsung internet 16.0 browser. I was not able to reproduce the issue myself, but it might be worth looking into. Here's a screenshot of the callstack: Screenshot 2022-02-10 at 13 53 24

I'm using npm package mixpanel-browser version 2.41.0.

tdumitrescu commented 2 years ago

Thanks for the report @sara-jegorova. Do you know whether you're passing any property values to track() that aren't simply serializable, for instance a native Error object as in https://github.com/mixpanel/mixpanel-js/issues/317? This infinite recursion issue happens when you pass an Object to track() that has a circular reference to itself somewhere, and you mention it only happens on one browser, hence the suspicion that you're tracking something as a prop that the browser has natively produced.

sara-jegorova commented 2 years ago

Hi @tdumitrescu , thanks for having a look. The only complex info I'm passing to track() is from reportWebVitals() in CRA which uses the web-vitals library, as it passes Metric: https://github.com/GoogleChrome/web-vitals/blob/main/src/types.ts#L39 . I think that if I just stop passing entries, these errors should go away.

tdumitrescu commented 2 years ago

Yes, generally you want to choose explicitly how to serialize values like that. This will also ensure that your tracking properties remain consistent across browsers.