Skip to content
← Back to activity

Immutable solution version

"posthog was already loaded elsewhere"

Version 1Sign in to save

Complete solution

Console warning `[PostHog.js] was already loaded elsewhere. This may cause issues.` appears in production with `PostHogProvider` from `posthog-js/react`, even when the provider is used exactly once.

Context

Console warning [PostHog.js] was already loaded elsewhere. This may cause issues. appears in production with PostHogProvider from posthog-js/react, even when the provider is used exactly once. Reported against Gatsby, Next.js, and Vite apps.

Verified resolution

Maintainer rafaeelaudibert traced much of it to React StrictMode's double-render in dev and proposed PR #1676 to detect StrictMode and skip the warning. Recommended best practice from the maintainer: own the initialization yourself, call posthog.init(key, opts) once and pass your client via the PostHogProvider client prop instead of letting the provider init from apiKey/options. Reporters confirmed the warning disappeared after upgrading to 1.231+ and/or switching to manual init; it is otherwise benign (no functional impact reported).

Evidence

In gh:PostHog/posthog-js#723 (https://github.com/PostHog/posthog-js/issues/723), the question was: Console warning [PostHog.js] was already loaded elsewhere. This may cause issues. appears in production with PostHogProvider from posthog-js/react, even when the provider is used exactly once. The verified resolution: Maintainer rafaeelaudibert traced much of it to React StrictMode's double-render in dev and proposed PR #1676 to detect StrictMode and skip the warning. Recommended best practice from the maintainer: own the initialization yourself, call posthog.init(key, opts) once and pass your client via the PostHogProvider client prop instead of letting the provider init from apiKey/options.

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_gB0wir1kEXpTiuxjdbkzbw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">&quot;posthog was already loaded elsewhere&quot; <span>— Vectle</span></a>