Skip to content

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

fix(reverse-proxy): suppress consent screen flash for orgs with records (#59719)

Fernando Gomesd128b4e12733
diff --git a/frontend/src/scenes/settings/environment/proxyLogic.test.ts b/frontend/src/scenes/settings/environment/proxyLogic.test.ts
index 49444927eeb6..1459d00f90f6 100644
--- a/frontend/src/scenes/settings/environment/proxyLogic.test.ts
+++ b/frontend/src/scenes/settings/environment/proxyLogic.test.ts
@@ -33,6 +33,9 @@ describe('proxyLogic — shouldShowCloudflareOptIn', () => {
let logic: ReturnType<typeof proxyLogic.build>
beforeEach(() => {
+ // cloudflareOptInAcknowledged is persisted to localStorage — wipe it so each test
+ // starts from a clean slate and isn't polluted by prior tests' acknowledgments.
+ localStorage.clear()
useMocks({
get: {
[`/api/organizations/${MOCK_ORGANIZATION_ID}/proxy_records`]: proxyRecordsResponse([]),
@@ -65,7 +68,7 @@ describe('proxyLogic — shouldShowCloudflareOptIn', () => {
})
})
- it('returns false when the organization already has proxy records, regardless of acknowledgment', async () => {
+ it('returns false when the organization already has proxy records', async () => {
useMocks({
get: {
[`/api/organizations/${MOCK_ORGANIZATION_ID}/proxy_records`]: proxyRecordsResponse([mockProxyRecord()]),
@@ -74,7 +77,6 @@ describe('proxyLogic — shouldShowCloudflareOptIn', () => {
await mountLogic()
await expectLogic(logic).toMatchValues({
- cloudflareOptInAcknowledged: false,
shouldShowCloudflareOptIn: false,
})
expect(logic.values.proxyRecords.length).toBeGreaterThan(0)
@@ -104,4 +106,31 @@ describe('proxyLogic — shouldShowCloudflareOptIn', () => {
shouldShowCloudflareOptIn: false,
})
})
+
+ it('does not show the banner before the initial records load resolves', () => {
+ // Mount synchronously without awaiting toFinishAllListeners — this mimics the
+ // first paint after mount, before the proxy_records API call has returned.
+ logic = proxyLogic()
+ logic.mount()
+
+ expect(logic.values.proxyRecordsLoaded).toBe(false)
+ expect(logic.values.shouldShowCloudflareOptIn).toBe(false)
+ })
+
+ it('auto-persists acknowledgment when loadRecordsSuccess returns existing records', async () => {
+ useMocks({
+ get: {
+ [`/api/organizations/${MOCK_ORGANIZATION_ID}/proxy_records`]: proxyRecordsResponse([mockProxyRecord()]),
+ },
+ })
+ await mountLogic()
+
+ // Records existing on the backend is durable proof of prior consent — the reducer
+ // re-persists this via { persist: true } so the banner doesn't flash again on
+ // browsers where localStorage was cleared.
+ await expectLogic(logic).toMatchValues({
+ cloudflareOptInAcknowledged: true,
+ shouldShowCloudflareOptIn: false,
+ })
+ })
})
diff --git a/frontend/src/scenes/settings/environment/proxyLogic.ts b/frontend/src/scenes/settings/environment/proxyLogic.ts
index 903bd02389b1..45f93be30330 100644
--- a/frontend/src/scenes/settings/environment/proxyLogic.ts
+++ b/frontend/src/scenes/settings/environment/proxyLogic.ts
@@ -134,6 +134,16 @@ export const proxyLogic = kea<proxyLogicType>([
{ persist: true },
{
acknowledgeCloudflareOptIn: () => true,
+ // Existing proxy records imply the org already consented previously — persist that so the
+ // banner doesn't flash on browsers where localStorage was cleared after records were created.
+ loadRecordsSuccess: (state, { proxyRecords }) => state || proxyRecords.length > 0,
+ },
+ ],
+ proxyRecordsLoaded: [
+ false,
+ {
+ loadRecordsSuccess: () => true,
+ loadRecordsFailure: () => true,
},
],
cloudflareOptInChecked: [
@@ -233,14 +243,19 @@ export const proxyLogic = kea<proxyLogicType>([
},
],
shouldShowCloudflareOptIn: [
- (s) => [s.cloudflareOptInAcknowledged, s.proxyRecords, s.user],
- (acknowledged: boolean, records: ProxyRecord[], user: UserType | null): boolean => {
+ (s) => [s.cloudflareOptInAcknowledged, s.proxyRecordsLoaded, s.proxyRecords, s.user],
+ (acknowledged: boolean, recordsLoaded: boolean, records: ProxyRecord[], user: UserType | null): boolean => {
if (acknowledged) {
return false
}
if (user?.is_impersonated) {
return false
}
+ // Wait for the initial records fetch — otherwise the banner flashes during the API call
+ // for orgs that already have proxy records, which is the visible symptom of #59549.
+ if (!recordsLoaded) {
+ return false
+ }
if (records.length > 0) {
return false
}