fix(analytics): Resolve feature flags before first render#2656
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
React Doctor found no issues in the changed files. 🎉 Reviewed by React Doctor for commit |
|
Reviews (1): Last reviewed commit: "initialize posthog before first render" | Re-trigger Greptile |
e29fc66 to
a32e3db
Compare
New commits pushed (delta classified non_linear_history) — stamphog approval dismissed; re-review running automatically.
There was a problem hiding this comment.
Low-risk analytics timing fix fully contained within the Electron host layer. The synchronous bootstrap path via contextBridge and additionalArguments is correct, the async fallback remains intact when the bootstrap value is absent, and the session ID is not sensitive data.
6e2fdfb to
975837d
Compare
a32e3db to
110c8db
Compare
New commits pushed (delta classified non_linear_history) — stamphog approval dismissed; re-review running automatically.
127a211 to
f04da06
Compare
New commits pushed (delta classified non_linear_history) — stamphog approval dismissed; re-review running automatically.
There was a problem hiding this comment.
Low-risk analytics timing fix fully contained in the Electron host layer. The idempotency guard in initializePostHog prevents double initialization, the async fallback is preserved when the sync bridge is absent, and the session ID is a non-sensitive analytics UUID.
f04da06 to
b704380
Compare
New commits pushed (delta classified non_linear_history) — stamphog approval dismissed; re-review running automatically.
There was a problem hiding this comment.
No showstoppers. Low-risk analytics timing fix fully contained within the Electron host layer — correct use of contextBridge and additionalArguments, the async fallback is preserved when the sync bridge is absent, and the session ID is a non-sensitive analytics UUID. Logic paths in main.tsx and app-boot.contributions.ts are consistent (sync path initializes PostHog, async path skips it, no double-init risk).

Problem
The "Cloud" option in the workspace-mode picker intermittently vanished on launch and only returned after a hard refresh or restart. It is gated by the
twig-cloud-mode-togglefeature flag, but the renderer deferred PostHog initialization behind an asyncgetSessionIdIPC round-trip. React mounted first, souseFeatureFlagread the flag asfalse(flags not loaded yet) and hid the option until init finished and flags arrived. EveryuseFeatureFlagconsumer was exposed to the same race; the|| import.meta.env.DEVfallback masked it during local development.Closes #2598
Changes
additionalArgumentswindow.__posthogBootstrapfrom the preloadAnalyticsBootContributionas an idempotent async fallback when the bridge value is absentHow did you test this?
pnpm --filter code typecheck(main + renderer tsconfigs) — passbiome checkon the changed files — clean (also enforced by the pre-commit hook)pnpm --filter code exec vitest run src/main/platform-adapters/posthog-analytics.test.ts— 7/7 passpnpm --filter @posthog/ui exec vitest run src/shell/posthogAnalyticsImpl.test.ts— 11/11 passNot yet run: an end-to-end check on a production build with
twig-cloud-mode-toggleenabled — the flag path is dev-forced on, so the race only manifests in production builds. A genuinely cold flag cache still has a one-time load window until the network flags response arrives, which is expected first-load behavior.Automatic notifications