posthog-js icon indicating copy to clipboard operation
posthog-js copied to clipboard

Maximum call stack size exceeded when working with Turbo

Open michael-yin opened this issue 2 years ago • 8 comments
trafficstars

I found posthog JS lib can not work with hotwired/turbo, which is a very popular frontend lib in Rails community.

If I click some links to do page navigation, then I will get the "Maximum call stack size exceeded"

And I think there might be some conflict between posthog-js and Turbo

Screen Shot 2023-06-01 at 3 21 12 PM

michael-yin avatar Jun 01 '23 07:06 michael-yin

I am having the same issue with HTMX

gsumo avatar Jun 16 '23 12:06 gsumo

This is a pretty prevalent issue with our next.js 13/turborepo setup, this happens ALL THE TIME:

image

hevans90 avatar Jun 19 '23 17:06 hevans90

I got 350k of these in a day for a very low volume website using Rails 7 + Turbo and Posthog. Might have to discontinue Posthog unless there's a fix!

jakeonrails avatar Sep 16 '23 02:09 jakeonrails

seeing this as well.

glassworks-projects avatar Jan 18 '24 18:01 glassworks-projects

Are there any updates on this? I'm running into the same issue.

evdevdev avatar Mar 28 '24 14:03 evdevdev

I don't have a rails site set up to test turbo but found this note in the docs

https://turbo.hotwired.dev/handbook/building#working-with-script-elements

Annotate

Are people with this problem using posthog via the snippet? If so can they try adding data-turbo-eval="false" to the script tag?

pauldambra avatar Mar 28 '24 23:03 pauldambra

I don't have a rails site set up to test turbo but found this note in the docs

https://turbo.hotwired.dev/handbook/building#working-with-script-elements

Annotate

Are people with this problem using posthog via the snippet? If so can they try adding data-turbo-eval="false" to the script tag?

@pauldambra - that could potentially work; however, there will be an issue when you explicitly want the script tag to be reevaluated.

For example, when someone goes from a logged out to logged in state and you'd want to add a posthog.identify call.

evdevdev avatar Mar 29 '24 20:03 evdevdev

when you explicitly want the script tag to be reevaluated. For example, when someone goes from a logged out to logged in state and you'd want to add a posthog.identify call.

There is for sure some mismatch between turbo and posthog-js here.

Posthog-js should be evaluated once per page load.

So, I think we need to be able to opt-out of turbo's behaviour which is what I was hoping data-turbo-eval="false". ofc if there's a better way to do it you all as users of turbo will likely figure it out better than us.

If you want to hold on to a reference to posthog so you can call identify, reset, capture etc that's fine (and the best way varies by application) but it shouldn't need you to evaluate the script tag more than once per page load

pauldambra avatar Apr 04 '24 13:04 pauldambra

Just installed today and currently getting slammed with these :/

Anyone ever find a workaround by any chance?

stuartchaney avatar May 31 '24 03:05 stuartchaney

So, I think we need to be able to opt-out of turbo's behaviour which is what I was hoping data-turbo-eval="false". ofc if there's a better way to do it you all as users of turbo will likely figure it out better than us.

If you want to hold on to a reference to posthog so you can call identify, reset, capture etc that's fine (and the best way varies by application) but it shouldn't need you to evaluate the script tag more than once per page load

Hey @stuartchaney are you able to test this?

pauldambra avatar May 31 '24 08:05 pauldambra

@stuartchaney The data-turbo-eval="false" has been working well for us.

evdevdev avatar May 31 '24 15:05 evdevdev

I'll close this since we've found out how to have the turbo and posthog co-exist peacefully here https://github.com/PostHog/posthog-js/issues/666#issuecomment-2026323030

thanks for bearing with us all

pauldambra avatar May 31 '24 16:05 pauldambra

@earnold @pauldambra - awesome, thank you both - implementing now.

stuartchaney avatar May 31 '24 17:05 stuartchaney

How can we add data-turbo-eval="false" while using the Next.js / React SDK? Not sure if related but this is happening on Next.js app dir turbopack. Absolutely destroys our Sentry events billing.

Screenshot 2024-07-12 at 8 58 55 PM

oalexdoda avatar Jul 12 '24 20:07 oalexdoda

Hey, just added the snippet to our NextJS site, and are seeing this issue. data-turbo-eval="false" has not resolved the error. Anyone have insight into other steps that have worked?

flamincode avatar Feb 27 '25 14:02 flamincode