: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(onboarding): stop reverse proxy nudge contradicting setup checklist (#61761)
Paul D'Ambraf9c64b34d56a
diff --git a/frontend/src/layout/navigation/projectNoticeLogic.test.ts b/frontend/src/layout/navigation/projectNoticeLogic.test.tsindex f48c47b36a28..8225db57bb28 100644--- a/frontend/src/layout/navigation/projectNoticeLogic.test.ts+++ b/frontend/src/layout/navigation/projectNoticeLogic.test.ts@@ -2,7 +2,9 @@ import { MOCK_TEAM_ID } from 'lib/api.mock'import { expectLogic } from 'kea-test-utils'+import { reverseProxyCheckerLogic } from 'lib/components/ReverseProxyChecker/reverseProxyCheckerLogic'import { verifyEmailLogic } from 'scenes/authentication/verify-email/verifyEmailLogic'+import { preflightLogic } from 'scenes/PreflightCheck/preflightLogic'import { useMocks } from '~/mocks/jest'import { initKeaTests } from '~/test/init'@@ -68,6 +70,110 @@ describe('projectNoticeLogic', () => {})})+ describe('reverse proxy checker connection', () => {+ let getItemSpy: jest.SpyInstance+ let getDateSpy: jest.SpyInstance++ beforeEach(() => {+ useMocks({+ get: {+ // currentOrganizationId resolves to the loaded org id, not "@current" —+ // match any id so loadRecords resolves instead of erroring.+ '/api/organizations/:organization_id/proxy_records': [200, { results: [] }],+ },+ post: {+ // reverseProxyCheckerLogic's HogQL detection query.+ '/api/environments/:team_id/query/:kind': () => [200, { results: [] }],+ },+ })+ initKeaTests()+ getItemSpy = jest.spyOn(Storage.prototype, 'getItem').mockImplementation(() => null)+ getDateSpy = jest.spyOn(Date.prototype, 'getDate')+ })++ afterEach(() => {+ getItemSpy.mockRestore()+ getDateSpy.mockRestore()+ })++ it.each([+ { label: 'inside the nudge window', dayOfMonth: 3 },+ { label: 'outside the nudge window', dayOfMonth: 15 },+ ])('mounts the connected checker $label and tears it down on unmount', async ({ dayOfMonth }) => {+ getDateSpy.mockReturnValue(dayOfMonth)++ const logic = projectNoticeLogic()+ logic.mount()++ // Connected via connect(), so it mounts with projectNoticeLogic regardless of the date gate.+ expect(reverseProxyCheckerLogic.isMounted()).toBe(true)+ // Let the auto-triggered detection settle so no async work outlives the test.+ await expectLogic(reverseProxyCheckerLogic).toDispatchActions(['loadHasReverseProxySuccess'])++ logic.unmount()+ expect(reverseProxyCheckerLogic.isMounted()).toBe(false)+ })+ })++ describe('reverse proxy banner suppression', () => {+ let getItemSpy: jest.SpyInstance+ let getDateSpy: jest.SpyInstance++ beforeEach(() => {+ useMocks({+ get: {+ '/api/organizations/:organization_id/proxy_records': [200, { results: [] }],+ },+ post: {+ '/api/environments/:team_id/query/:kind': () => [200, { results: [] }],+ },+ })+ initKeaTests()+ // isCloudOrDev gates the nudge — self-hosted users manage their own infrastructure.+ preflightLogic.actions.loadPreflightSuccess({ cloud: true } as any)+ getItemSpy = jest.spyOn(Storage.prototype, 'getItem').mockImplementation(() => null)+ // Inside the first-7-days nudge window.+ getDateSpy = jest.spyOn(Date.prototype, 'getDate').mockReturnValue(3)+ })++ afterEach(() => {+ getItemSpy.mockRestore()+ getDateSpy.mockRestore()+ })++ // Drives the projectNoticeVariant selector deterministically: wait for the checker's+ // auto-load to settle, then force the detection result and an empty managed-proxy list so+ // the assertion doesn't depend on async msw timing. A forced value wins because it is+ // dispatched after the awaited auto-load.+ const mountWithDetectedProxy = async (+ hasReverseProxy: boolean+ ): Promise<ReturnType<typeof projectNoticeLogic>> => {+ const logic = projectNoticeLogic()+ logic.mount()+ await expectLogic(reverseProxyCheckerLogic).toDispatchActions(['loadHasReverseProxySuccess'])+ reverseProxyCheckerLogic.actions.loadHasReverseProxySuccess(hasReverseProxy)+ logic.actions.loadRecordsSuccess([])+ return logic+ }++ it('suppresses the nudge when a self-managed proxy is detected', async () => {+ const logic = await mountWithDetectedProxy(true)++ // Zero managed proxy records, but a DIY proxy is routing events — the banner must not nag.+ expect(logic.values.projectNoticeVariant).not.toEqual('missing_reverse_proxy')++ logic.unmount()+ })++ it('shows the nudge when no proxy exists and there are no managed records', async () => {+ const logic = await mountWithDetectedProxy(false)++ expect(logic.values.projectNoticeVariant).toEqual('missing_reverse_proxy')++ logic.unmount()+ })+ })+describe('unverified email banner CTA', () => {beforeEach(() => {useMocks({diff --git a/frontend/src/layout/navigation/projectNoticeLogic.tsx b/frontend/src/layout/navigation/projectNoticeLogic.tsxindex e40bf24e20ea..fb3b9c8a9335 100644--- a/frontend/src/layout/navigation/projectNoticeLogic.tsx+++ b/frontend/src/layout/navigation/projectNoticeLogic.tsx@@ -5,6 +5,7 @@ import { router } from 'kea-router'import { IconGear, IconPlus } from '@posthog/icons'import api from 'lib/api'+import { reverseProxyCheckerLogic } from 'lib/components/ReverseProxyChecker/reverseProxyCheckerLogic'import { superpowersLogic } from 'lib/components/Superpowers/superpowersLogic'import { LemonBannerProps } from 'lib/lemon-ui/LemonBanner/LemonBanner'import { Link } from 'lib/lemon-ui/Link'@@ -116,7 +117,19 @@ export const projectNoticeLogic = kea<projectNoticeLogicType>([path(['layout', 'navigation', 'projectNoticeLogic']),connect(() => ({logic: [verifyEmailLogic],- values: [membersLogic, ['memberCount'], organizationLogic, ['currentOrganizationId']],+ values: [+ membersLogic,+ ['memberCount'],+ organizationLogic,+ ['currentOrganizationId'],+ // Connecting reverseProxyCheckerLogic mounts it and exposes hasReverseProxy reactively.+ // A self-managed (DIY) reverse proxy never appears in proxy_records, but it does stamp+ // $lib_custom_api_host on events, which the checker detects — this keeps the "set up a+ // reverse proxy" nudge from contradicting the onboarding checklist, which marks the task+ // complete on the same signal. The checker throttles its own detection query internally.+ reverseProxyCheckerLogic,+ ['hasReverseProxy'],+ ],actions: [eventUsageLogic,['reportProjectNoticeDismissed', 'reportProjectNoticeShown'],@@ -173,6 +186,8 @@ export const projectNoticeLogic = kea<projectNoticeLogicType>([s.noticeDismissedThisSession,sceneLogic.selectors.activeSceneId,(state) => liveEventsLogic.findMounted()?.selectors.eventCount(state) ?? 0,+ // null = not yet checked; we only nudge once detection confirms there's no proxy.+ s.hasReverseProxy,],(organization,@@ -188,7 +203,8 @@ export const projectNoticeLogic = kea<projectNoticeLogicType>([currentLocation,noticeDismissedThisSession,activeSceneId,- liveEventCount+ liveEventCount,+ hasReverseProxy): ProjectNoticeVariant | null => {if (!organization) {return null@@ -234,7 +250,11 @@ export const projectNoticeLogic = kea<projectNoticeLogicType>([isCloudOrDev &&shouldFetchProxyRecords() &&proxyRecords !== null &&- proxyRecords.length === 0+ proxyRecords.length === 0 &&+ // ...and only once the checker has confirmed there's no self-managed proxy+ // routing events. While it's still null (not yet checked) we hold the nudge+ // back to avoid flashing it at DIY-proxy users before detection resolves.+ hasReverseProxy === false) {return 'missing_reverse_proxy'} else if (!isNoticeDismissed('invite_teammates') && memberCount === 1) {diff --git a/frontend/src/lib/components/ReverseProxyChecker/reverseProxyCheckerLogic.test.ts b/frontend/src/lib/components/ReverseProxyChecker/reverseProxyCheckerLogic.test.tsindex 6dfd8cf2572c..6a6df0a12bb4 100644--- a/frontend/src/lib/components/ReverseProxyChecker/reverseProxyCheckerLogic.test.ts+++ b/frontend/src/lib/components/ReverseProxyChecker/reverseProxyCheckerLogic.test.ts@@ -100,7 +100,9 @@ describe('reverseProxyCheckerLogic', () => {}).toFinishAllListeners().toMatchValues({- hasReverseProxy: false,+ // On error with no prior successful load the status stays unknown (null) rather+ // than a confirmed false — consumers gate on `=== false`, so this fails safe.+ hasReverseProxy: null,})expect(toastErrorSpy).not.toHaveBeenCalled()diff --git a/frontend/src/lib/components/ReverseProxyChecker/reverseProxyCheckerLogic.ts b/frontend/src/lib/components/ReverseProxyChecker/reverseProxyCheckerLogic.tsindex fdccb3444170..44818de1ae8d 100644--- a/frontend/src/lib/components/ReverseProxyChecker/reverseProxyCheckerLogic.ts+++ b/frontend/src/lib/components/ReverseProxyChecker/reverseProxyCheckerLogic.ts@@ -16,7 +16,9 @@ export const reverseProxyCheckerLogic = kea<reverseProxyCheckerLogicType>([path(['components', 'ReverseProxyChecker', 'reverseProxyCheckerLogic']),loaders(({ values, cache }) => ({hasReverseProxy: [- false as boolean | null,+ // null until the detection query resolves — consumers must distinguish "not yet+ // checked" from a confirmed `false` so they don't act before the result is in.+ null as boolean | null,{loadHasReverseProxy: async () => {if (cache.lastCheckedTimestamp > Date.now() - CHECK_INTERVAL_MS) {