Skip to content

Conversation

areibman
Copy link
Contributor

@areibman areibman commented Sep 10, 2025

📥 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

  1. Ran the application in local development mode.
  2. Verified that no PostHog-related errors (401, 404, MIME type) appear in the browser console.
  3. Confirmed that the core application functionality remains unaffected.

Open in Cursor Open in Web

Only initialize PostHog in production and when a key is present.
Ensure PostHog is loaded before identifying users.

Co-authored-by: meta.alex.r <[email protected]>
Copy link

cursor bot commented Sep 10, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@areibman areibman marked this pull request as ready for review September 16, 2025 03:15
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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".

Comment on lines 11 to +15
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, {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants