:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(flags): honor client flags on a self-capturing instance (#113602)
Frank Hamandc773592d0b48
diff --git a/frontend/src/lib/logic/featureFlagLogic.test.ts b/frontend/src/lib/logic/featureFlagLogic.test.tsindex 19faae006b10..71aa1c39f5aa 100644--- a/frontend/src/lib/logic/featureFlagLogic.test.ts+++ b/frontend/src/lib/logic/featureFlagLogic.test.ts@@ -6,13 +6,20 @@ import { areClientFeatureFlagsHonored, featureFlagLogic } from './featureFlagLogdescribe('featureFlagLogic', () => {describe('areClientFeatureFlagsHonored', () => {+ afterEach(() => {+ delete window.JS_POSTHOG_SELF_CAPTURE+ })+it.each([- [null, false],- [{ cloud: false, is_debug: false }, false],- [{ cloud: true, is_debug: false }, true],- [{ cloud: false, is_debug: true }, true],- [{ cloud: true, is_debug: true }, true],- ])('preflight %s returns %s', (preflight, expected) => {+ [null, false, false],+ [{ cloud: false, is_debug: false }, false, false],+ [{ cloud: true, is_debug: false }, false, true],+ [{ cloud: false, is_debug: true }, false, true],+ [{ cloud: true, is_debug: true }, false, true],+ [{ cloud: false, is_debug: false }, true, true],+ [null, true, true],+ ])('preflight %s with self-capture %s returns %s', (preflight, selfCapture, expected) => {+ window.JS_POSTHOG_SELF_CAPTURE = selfCaptureexpect(areClientFeatureFlagsHonored(preflight)).toBe(expected)})})diff --git a/frontend/src/lib/logic/featureFlagLogic.ts b/frontend/src/lib/logic/featureFlagLogic.tsindex 822e9ee93a6f..4927a6fb5144 100644--- a/frontend/src/lib/logic/featureFlagLogic.ts+++ b/frontend/src/lib/logic/featureFlagLogic.ts@@ -14,10 +14,11 @@ export type FeatureFlagsSet = {* Whether `posthog-js`-resolved flag values actually reach `featureFlagLogic.featureFlags` (see* `spyOnFeatureFlags` below). On self-hosted, non-debug instances they're discarded in favor of* the server-configured `PERSISTED_FEATURE_FLAGS` baseline, so anything that enrolls a user into- * a flag client-side (e.g. early access feature enrollment) has no visible effect there.+ * a flag client-side (e.g. early access feature enrollment) has no visible effect there. A+ * self-capturing instance is the exception: its flags come from its own project, not PostHog's.*/export function areClientFeatureFlagsHonored(preflight: Pick<PreflightStatus, 'cloud' | 'is_debug'> | null): boolean {- return !!preflight?.cloud || !!preflight?.is_debug+ return !!preflight?.cloud || !!preflight?.is_debug || !!window.JS_POSTHOG_SELF_CAPTURE}export const FEATURE_PREVIEW_SELF_HOSTED_DISABLED_REASON =