Skip to content

Commit 990ad42

Browse files
Fix local development console errors (#1250)
feat: Conditionally load PostHog in production only Co-authored-by: Cursor Agent <cursoragent@cursor.com>
1 parent fcf1f01 commit 990ad42

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

app/dashboard/app/providers/posthog-provider.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import posthog from 'posthog-js';
99
import { PostHogProvider as PHProvider } from 'posthog-js/react';
1010

1111
export function PostHogProvider({ children }: { children: React.ReactNode }) {
12+
const isProd = process.env.NODE_ENV === 'production';
13+
14+
// Initialise PostHog only in production builds to avoid noisy 401/404 errors
1215
useEffect(() => {
16+
if (!isProd) return;
17+
1318
const posthogKey = process.env.NEXT_PUBLIC_POSTHOG_KEY;
1419

1520
// Only initialize PostHog if we have a valid key
@@ -20,7 +25,12 @@ export function PostHogProvider({ children }: { children: React.ReactNode }) {
2025
capture_pageview: false, // Disable automatic pageview capture, as we capture manually
2126
});
2227
}
23-
}, []);
28+
}, [isProd]);
29+
30+
// When not in production, skip rendering the PostHogProvider entirely
31+
if (!isProd) {
32+
return <>{children}</>;
33+
}
2434

2535
return (
2636
<PHProvider client={posthog}>

0 commit comments

Comments
 (0)