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

Better support for SSR - graceful handling of method calls without init()

Open paolodamico opened this issue 3 years ago • 1 comments

If you're running your frontend with server-side rendering you need to wrap up all function calls to PostHog to only run after posthog.init() has been called. As a user suggested (original thread), we could do the same thing that Sentry SDK does. If you call methods (such as isFeatureEnabled, capture, identify or reset) without having called posthog.init(), we could simply have a noop instead of raising an error. We could consider just logging a warning to make sure this doesn't fail silently if you accidentally forget to add the posthog.init() call.

paolodamico avatar Apr 07 '21 02:04 paolodamico

Have been dealing with this exact issue when testing component-level stories via Storybook.

Have to try/catch every posthog call to avoid breaking the story when calling posthog.capture :-)

danielthedifficult avatar Aug 31 '21 10:08 danielthedifficult

This issue hasn't seen activity in two years! If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in two weeks.

posthog-bot avatar Sep 01 '23 09:09 posthog-bot

This issue was closed due to lack of activity. Feel free to reopen if it's still relevant.

posthog-bot avatar Sep 18 '23 09:09 posthog-bot