88} from "@tanstack/react-router" ;
99import { TanStackRouterDevtools } from "@tanstack/react-router-devtools" ;
1010import posthog from "posthog-js" ;
11+ import { PropsWithChildren , useEffect } from "react" ;
1112import { CookiesProvider } from "react-cookie" ;
1213import "react-reflex/styles.css" ;
1314import "typeface-roboto-mono/index.css" ; // Import the Roboto Mono font.
@@ -55,12 +56,19 @@ const routeTree = rootRoute.addChildren([indexRoute, inlineRoute, embeddedRoute]
5556const router = createRouter ( { routeTree } ) ;
5657
5758const config = AppConfig ( ) ;
58- if ( config . posthog . apiKey && config . posthog . host ) {
59- posthog . init ( config . posthog . apiKey , {
60- api_host : config . posthog . host ,
61- person_profiles : "identified_only" ,
62- defaults : "2025-11-30" , // Enables automatic SPA pageview tracking via history API
63- } ) ;
59+
60+ function PHProvider ( { children } : PropsWithChildren ) {
61+ useEffect ( ( ) => {
62+ if ( config . posthog . apiKey && config . posthog . host ) {
63+ posthog . init ( config . posthog . apiKey , {
64+ api_host : config . posthog . host ,
65+ person_profiles : "identified_only" ,
66+ defaults : "2025-11-30" , // Enables automatic SPA pageview tracking via history API
67+ } ) ;
68+ }
69+ } , [ ] ) ;
70+
71+ return < PostHogProvider client = { posthog } > { children } </ PostHogProvider > ;
6472}
6573
6674function App ( ) {
@@ -73,15 +81,15 @@ function App() {
7381 < Toaster />
7482 { /* @ts -ignore-error react-cookie's types are screwy; CI and (local and vercel) disagree about whether there's an error or not. */ }
7583 < CookiesProvider >
76- < PostHogProvider client = { posthog } >
84+ < PHProvider >
7785 < ThemeProvider >
7886 < PlaygroundUIThemed { ...PLAYGROUND_UI_COLORS } forceDarkMode = { isEmbeddedPlayground } >
7987 < ConfirmDialogProvider >
8088 < RouterProvider router = { router } />
8189 </ ConfirmDialogProvider >
8290 </ PlaygroundUIThemed >
8391 </ ThemeProvider >
84- </ PostHogProvider >
92+ </ PHProvider >
8593 </ CookiesProvider >
8694 </ >
8795 ) ;
0 commit comments