: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): resolve step ids against the flow, not the key list (#78516)
Matt Brooker596c79d63397
diff --git a/frontend/src/scenes/onboarding/legacy/onboardingLogic.test.ts b/frontend/src/scenes/onboarding/legacy/onboardingLogic.test.tsindex 6c307103d2c5..3c0790507816 100644--- a/frontend/src/scenes/onboarding/legacy/onboardingLogic.test.ts+++ b/frontend/src/scenes/onboarding/legacy/onboardingLogic.test.ts@@ -372,6 +372,35 @@ describe('onboardingLogic — flow composition', () => {expect(logic.values.stepId).toBe('')expect(logic.values.currentFlowStep?.id).toBe('install:web_analytics')})++ it('self-corrects a valid step key the flow has no step for', async () => {+ // Product selection always routes to ?step=install, but Support's flow has no+ // install step, so a key being valid is not reason enough to keep waiting on it.+ logic.actions.setProductKey(ProductKey.CONVERSATIONS)+ logic.actions.setStepId(OnboardingStepKey.INSTALL)+ await new Promise((resolve) => setTimeout(resolve, 0))+ expect(logic.values.stepId).toBe('')+ expect(logic.values.currentFlowStep?.id).toBe('invite_teammates:conversations')+ })++ it('self-corrects link_data when the flow will never carry it', async () => {+ // `link_data` is gated on the product keys alone, which are set before the step is,+ // so for a primary that never gets it there is nothing to wait for.+ logic.actions.setProductKey(ProductKey.WEB_ANALYTICS)+ logic.actions.setStepId(OnboardingStepKey.LINK_DATA)+ await new Promise((resolve) => setTimeout(resolve, 0))+ expect(logic.values.stepId).toBe('')+ expect(logic.values.currentFlowStep?.id).toBe('install:web_analytics')+ })++ it('holds a shared trailing step open until it is appended', async () => {+ // `plans` joins the flow only once billing loads, which it has not here.+ // Self-correcting it would lose the request before the flow settles.+ logic.actions.setProductKey(ProductKey.WEB_ANALYTICS)+ logic.actions.setStepId(OnboardingStepKey.PLANS)+ await new Promise((resolve) => setTimeout(resolve, 0))+ expect(logic.values.stepId).toBe(OnboardingStepKey.PLANS)+ })})describe('navigation', () => {diff --git a/frontend/src/scenes/onboarding/legacy/onboardingLogic.tsx b/frontend/src/scenes/onboarding/legacy/onboardingLogic.tsxindex c8c8173f3fb0..8d4cdad8c07f 100644--- a/frontend/src/scenes/onboarding/legacy/onboardingLogic.tsx+++ b/frontend/src/scenes/onboarding/legacy/onboardingLogic.tsx@@ -37,7 +37,7 @@ import type {} from '../../../types'import { onboardingEventUsageLogic } from '../onboardingEventUsageLogic'import { arraysEqual, parseProductsParam, stepKeyToTitle } from './onboardingFlowUtils'-import { appendSharedTrailingSteps } from './sharedSteps'+import { appendSharedTrailingSteps, mayBeAppendedLater } from './sharedSteps'import { onboardingProviderRegistry } from './stepProviderRegistry'import { type OnboardingFlowContext, type OnboardingStepDescriptor } from './types'@@ -913,19 +913,17 @@ export const onboardingLogic = kea<onboardingLogicType>([// `currentFlowStep` returns null and the host shows a spinner forever.// Reconcile by falling through to flow[0].//- // Important: only self-correct when the stepId is genuinely unknown — NOT when- // it's a valid OnboardingStepKey that simply hasn't been emitted into the flow- // yet. Steps like `plans` are appended async (after billing loads) by- // `appendSharedTrailingSteps`; self-correcting too eagerly here would clobber- // the URL before the flow settles, leaving the user on `flow[0]` even after- // billing arrives.- // A `?` or `&` means query params fused into the step value (a mangled URL) — never- // treat that as a valid namespaced id, or self-correction skips it and the host- // spins forever waiting for a step that can't resolve.- const isKnownStepKey = (id: string): boolean =>- !/[?&]/.test(id) &&- (Object.values(OnboardingStepKey).includes(id as OnboardingStepKey) || id.includes(':'))- if (stepId && values.flow.length > 0 && !isKnownStepKey(stepId)) {+ // Important: hold the URL open for a step that hasn't been emitted into the flow+ // yet. Only `appendSharedTrailingSteps` adds steps late (after billing and org data+ // load), so `mayBeAppendedLater` is the whole set worth waiting on; self-correcting+ // those too eagerly would clobber the URL before the flow settles, leaving the user+ // on `flow[0]` even after billing arrives.+ //+ // Every other key has to resolve against the flow it was built for. Treating a valid+ // key as reason enough to wait strands any product whose flow lacks that step — a+ // product with no install step still routes to `?step=install` on selection, and the+ // host then spins forever on a step that is never coming.+ if (stepId && values.flow.length > 0 && !mayBeAppendedLater(stepId)) {const exact = values.flow.find((step) => step.id === stepId)const loose = exact ? null : values.flow.find((step) => step.stepKey === stepId)if (!exact && !loose) {@@ -1023,17 +1021,14 @@ export const onboardingLogic = kea<onboardingLogicType>([// through urlToAction and re-dispatches setStepId(bogus), looping// indefinitely. Stripping unresolvable stepIds here keeps the URL// self-consistent with the reducer state.- // Mirror the `setStepId` listener's `isKnownStepKey` heuristic. Billing-gated- // steps (plans, invite_teammates, link_data) are appended async after billing- // loads, so they may not be in `flow` when the URL push lands. Stripping them- // from the URL would re-fire `setStepId('')` and permanently lose the request.- const isKnownStepKey =- !/[?&]/.test(stepId) &&- (Object.values(OnboardingStepKey).includes(stepId as OnboardingStepKey) || stepId.includes(':'))+ // Mirror the `setStepId` listener's hold-open rule. The shared trailing steps are+ // appended async after billing and org data load, so they may not be in `flow` when+ // the URL push lands. Stripping them would re-fire `setStepId('')` and permanently+ // lose the request.const stepResolves =!stepId ||values.flow.length === 0 ||- isKnownStepKey ||+ mayBeAppendedLater(stepId) ||!!values.flow.find((s) => s.id === stepId || s.stepKey === stepId)// The first tuple element must be a bare pathname: kea-router joins the tuple by// string concatenation (`path + '?' + search`), so a query embedded here would get adiff --git a/frontend/src/scenes/onboarding/legacy/sharedSteps.tsx b/frontend/src/scenes/onboarding/legacy/sharedSteps.tsxindex 00c249c96972..1401dc9a3d9f 100644--- a/frontend/src/scenes/onboarding/legacy/sharedSteps.tsx+++ b/frontend/src/scenes/onboarding/legacy/sharedSteps.tsx@@ -8,6 +8,32 @@ import { OnboardingAIReports } from './notifications/OnboardingAIReports'import { OnboardingInviteTeammates } from './OnboardingInviteTeammates'import { OnboardingFlowContext, OnboardingStepDescriptor } from './types'+// The only step keys that join a flow after it first renders. Each is gated on data that arrives+// asynchronously (billing, organization, feature flags), so a URL targeting one has to be held+// open until that data settles. `link_data` is deliberately absent: it is gated on the primary and+// secondary product keys alone, both of which are set from the URL before the step is, so it is+// either in the flow immediately or never. Keep in sync with the pushes below.+const ASYNC_TRAILING_STEP_KEYS = new Set<string>([+ OnboardingStepKey.PLANS,+ OnboardingStepKey.INVITE_TEAMMATES,+ OnboardingStepKey.AI_REPORTS,+])++/**+ * Whether a stepId could still be appended to the flow, so an unresolved URL targeting it is+ * worth holding open rather than self-correcting. Any other key either resolves against the+ * flow it was built for or never will.+ */+export function mayBeAppendedLater(stepId: string): boolean {+ // A `?` or `&` means query params fused into the step value, which is a mangled URL rather+ // than a step anything is waiting on.+ if (/[?&]/.test(stepId)) {+ return false+ }+ const [stepKey] = stepId.split(':')+ return ASYNC_TRAILING_STEP_KEYS.has(stepKey)+}+export function appendSharedTrailingSteps(steps: OnboardingStepDescriptor[],ctx: OnboardingFlowContext,