Conversation
Only initialize PostHog in production and when a key is present. Ensure PostHog is loaded before identifying users. Co-authored-by: meta.alex.r <meta.alex.r@gmail.com>
|
Cursor Agent can help with this pull request. Just |
There was a problem hiding this comment.
Codex Review: Here are some suggestions.
Reply with @codex fix comments to fix any unresolved comments.
About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".
| useEffect(() => { | ||
| if (posthog && user?.id) { | ||
| posthog.identify(user.id, { | ||
| email: user.email || undefined, | ||
| name: user.full_name || undefined, | ||
| }); | ||
| } else if (posthog && !user) { | ||
| posthog.reset(); | ||
| // Only proceed if PostHog is available and initialized | ||
| if (posthog && posthog.__loaded) { | ||
| if (user?.id) { | ||
| posthog.identify(user.id, { |
There was a problem hiding this comment.
[P1] Avoid gating user identification on posthog.__loaded
The effect now skips identify until posthog.__loaded is true, but the dependency array only tracks the PostHog object reference and the user. When the user data resolves before the PostHog script finishes loading, the effect runs with __loaded === false and exits, then never re‑runs after initialization because neither dependency changes. The user is therefore never identified and all subsequent events remain anonymous. Consider removing the __loaded guard or triggering the effect again when the initialization flag flips.
Useful? React with 👍 / 👎.
📥 Pull Request
📘 Description
Resolved numerous console errors occurring in local development mode by conditionally disabling PostHog initialization and improving its integration to gracefully handle missing keys or uninitialized states. This prevents 401, 404, and MIME type errors related to PostHog when running locally.
🧪 Testing