posthog-js
posthog-js copied to clipboard
PostHog crashing with Uncaught RangeError: Maximum call stack size exceeded in a specific situation when loading the script twice
Bug description
Upon login, the PostHog script runs an infinite loop and kind of crashes. No events are sent to the cloud afterwards. Only happens when logging in to the app, if I refresh the page the error is gone.
The bug is a bit hard to reproduce, but I believe I might have found the root cause of the issue:
My app was loading the script twice, once in the /login page, and once again upon login (SPA kind of app, no page refresh upon login). <script type="text/javascript" async="" src="https://eu.posthog.com/static/array.js"></script>
Please describe.
Here is a video showing off the bug: https://watch.screencastify.com/v/n4o2NlWRj1N7oXpopdPI
At the end of the video, I notice the PostHog script is loaded twice in the DOM.
Following through, I've made sure to load the PostHog script only once per page, and the error vanished. But I still think I should report it, as I might not have found the actual root cause, I'm barely guessing here.
VM21 array.js:1 Uncaught RangeError: Maximum call stack size exceeded
at e.value (VM21 array.js:1:73634)
at t.<computed> [as capture] (unly-recrutement-head.js?t=1666348889:formatted:264:27)
at e.<anonymous> (VM21 array.js:1:73306)
at Array.forEach (<anonymous>)
at L (VM21 array.js:1:10704)
at s (VM21 array.js:1:73203)
at e.value (VM21 array.js:1:73355)
at e.value (VM21 array.js:1:73634)
at t.<computed> [as capture] (unly-recrutement-head.js?t=1666348889:formatted:264:27)
at e.<anonymous> (VM21 array.js:1:73306)
at Array.forEach (<anonymous>)
at L (VM21 array.js:1:10704)
at s (VM21 array.js:1:73203)
at e.value (VM21 array.js:1:73355)
at e.value (VM21 array.js:1:73634)
at t.<computed> [as capture] (unly-recrutement-head.js?t=1666348889:formatted:264:27)
at e.<anonymous> (VM21 array.js:1:73306)
at Array.forEach (<anonymous>)
at L (VM21 array.js:1:10704)
at s (VM21 array.js:1:73203)
at e.value (VM21 array.js:1:73355)
at e.value (VM21 array.js:1:73634)
at t.<computed> [as capture] (unly-recrutement-head.js?t=1666348889:formatted:264:27)
at e.<anonymous> (VM21 array.js:1:73306)
at Array.forEach (<anonymous>)
at L (VM21 array.js:1:10704)
at s (VM21 array.js:1:73203)
at e.value (VM21 array.js:1:73355)
at e.value (VM21 array.js:1:73634)
at t.<computed> [as capture] (unly-recrutement-head.js?t=1666348889:formatted:264:27)
at e.<anonymous> (VM21 array.js:1:73306)
at Array.forEach (<anonymous>)
at L (VM21 array.js:1:10704)
at s (VM21 array.js:1:73203)
at e.value (VM21 array.js:1:73355)
at e.value (VM21 array.js:1:73634)
at t.<computed> [as capture] (unly-recrutement-head.js?t=1666348889:formatted:264:27)
at e.<anonymous> (VM21 array.js:1:73306)
at Array.forEach (<anonymous>)
at L (VM21 array.js:1:10704)
at s (VM21 array.js:1:73203)
at e.value (VM21 array.js:1:73355)
at e.value (VM21 array.js:1:73634)
at t.<computed> [as capture] (unly-recrutement-head.js?t=1666348889:formatted:264:27)
at e.<anonymous> (VM21 array.js:1:73306)
at Array.forEach (<anonymous>)
at L (VM21 array.js:1:10704)
at s (VM21 array.js:1:73203)
at e.value (VM21 array.js:1:73355)
How to reproduce
- Load twice the posthog script and try to init twice, too?
Environment
- [x] PostHog Cloud
Additional context
Note that the issue with events not being sent was actually a different issue, which was caused by posthog.init being called twice in my code, but the loaded event would only be called once, and therefore all the code used to identify the current user wasn't invoked at all.