: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): scope the quick start highlight to its route (#100689)
posthog[bot]c26a1fca06a7
diff --git a/frontend/src/lib/components/ProductSetup/globalSetupLogic.ts b/frontend/src/lib/components/ProductSetup/globalSetupLogic.tsindex 9b9cbe0433be..f1482ad4319e 100644--- a/frontend/src/lib/components/ProductSetup/globalSetupLogic.ts+++ b/frontend/src/lib/components/ProductSetup/globalSetupLogic.ts@@ -1,4 +1,5 @@import { MakeLogicType, actions, connect, kea, listeners, path, reducers, selectors } from 'kea'+import { router } from 'kea-router'import { subscriptions } from 'kea-subscriptions'import posthog from 'posthog-js'@@ -11,12 +12,18 @@ import { ActivationTaskStatus } from '~/types'import type { AvailableSetupTaskIdsEnumApi } from '../../../generated/core/api.schemas'import { PRODUCTS_WITH_SETUP } from './productSetupRegistry'+import type { SetupHighlight } from './types'// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface globalSetupLogicValues {+ location: {+ pathname: string+ search: string+ hash: string+ } // routeractiveSceneProductKey: ProductKey | null // sceneLogicavailableProducts: ProductKey[]- highlightSelector: string | null+ highlight: SetupHighlight | nullisGlobalModalOpen: booleanisProductSelectionLocked: booleanoptimisticTaskStatuses: Record<string, ActivationTaskStatus | null>@@ -27,7 +34,7 @@ export interface globalSetupLogicValues {// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface globalSetupLogicActions {- clearHighlightSelector: () => {+ clearHighlight: () => {value: true}clearOptimisticTaskStatuses: (taskIds: SetupTaskId[]) => {@@ -45,8 +52,12 @@ export interface globalSetupLogicActions {openGlobalSetup: () => {value: true}- setHighlightSelector: (selector: string | null) => {- selector: string | null+ setHighlight: (+ selector: string,+ pathname: string+ ) => {+ pathname: string+ selector: string}setOptimisticTaskStatuses: (statuses: Record<string, ActivationTaskStatus | null>) => {statuses: Record<string, ActivationTaskStatus | null>@@ -91,7 +102,7 @@ export type globalSetupLogicType = MakeLogicType<export const globalSetupLogic = kea<globalSetupLogicType>([path(['lib', 'components', 'ProductSetup', 'globalSetupLogic']),connect(() => ({- values: [sceneLogic, ['activeSceneProductKey']],+ values: [router, ['location'], sceneLogic, ['activeSceneProductKey']],})),actions({// Task actions - single source of truth for task state updates@@ -112,8 +123,8 @@ export const globalSetupLogic = kea<globalSetupLogicType>([closeGlobalSetup: true,// Element highlighting after navigation- setHighlightSelector: (selector: string | null) => ({ selector }),- clearHighlightSelector: true,+ setHighlight: (selector: string, pathname: string) => ({ selector, pathname }),+ clearHighlight: true,}),reducers({// Currently selected product in the global setup popover@@ -131,12 +142,13 @@ export const globalSetupLogic = kea<globalSetupLogicType>([closeGlobalSetup: () => false,},],- // Selector for element to highlight after navigation- highlightSelector: [- null as string | null,+ // Element to highlight after navigation, bound to the route that asked for it. An unbound+ // highlight outlives its route and pulses whatever matches on a page opened later.+ highlight: [+ null as SetupHighlight | null,{- setHighlightSelector: (_, { selector }) => selector,- clearHighlightSelector: () => null,+ setHighlight: (_, { selector, pathname }) => ({ selector, pathname }),+ clearHighlight: () => null,},],// Optimistic task statuses - updated immediately before API call completes@@ -324,6 +336,12 @@ export const globalSetupLogic = kea<globalSetupLogicType>([},})),subscriptions(({ actions, values }) => ({+ // Drop a pending highlight as soon as the user leaves the route that asked for it+ location: ({ pathname }: { pathname: string }) => {+ if (values.highlight && values.highlight.pathname !== pathname) {+ actions.clearHighlight()+ }+ },// When the scene product key changes, auto-select it in the popoversceneProductKey: (sceneProductKey: ProductKey | null) => {if (sceneProductKey && sceneProductKey !== values.selectedProduct) {diff --git a/frontend/src/lib/components/ProductSetup/productSetupLogic.test.ts b/frontend/src/lib/components/ProductSetup/productSetupLogic.test.tsindex 0658e533aae8..2ada01d14315 100644--- a/frontend/src/lib/components/ProductSetup/productSetupLogic.test.ts+++ b/frontend/src/lib/components/ProductSetup/productSetupLogic.test.ts@@ -1,12 +1,15 @@+import { router } from 'kea-router'import { expectLogic } from 'kea-test-utils'import { SetupTaskId } from 'lib/components/ProductSetup'import { teamLogic } from 'scenes/teamLogic'+import { urls } from 'scenes/urls'import { ProductKey } from '~/queries/schema/schema-general'import { initKeaTests } from '~/test/init'import { ActivationTaskStatus, TeamType } from '~/types'+import { globalSetupLogic } from './globalSetupLogic'import { productSetupLogic } from './productSetupLogic'import type { SetupTaskWithState } from './types'@@ -22,6 +25,7 @@ describe('productSetupLogic', () => {afterEach(() => {logic.unmount()+ jest.restoreAllMocks()})const task = (id: SetupTaskId): SetupTaskWithState =>@@ -54,6 +58,43 @@ describe('productSetupLogic', () => {expect(task(SetupTaskId.CreateFirstInsight).lockedReason).toContain('Ingest your first event')})+ // The reported bug: the highlight used to outlive the route that asked for it, so the pulse+ // landed on whatever matched the selector on a page the user opened later.+ it('drops a pending highlight when the user navigates away', async () => {+ await expectLogic(logic, () => logic.actions.runTask(SetupTaskId.CreateFirstInsight)).toFinishAllListeners()++ expect(globalSetupLogic.values.highlight).toEqual({+ selector: '[data-attr="saved-insights-new-insight-button"]',+ // getUrl() is project-relative, so the binding reads the route the router landed on+ pathname: expect.stringContaining(urls.insights()),+ })++ router.actions.push(urls.featureFlag('new'))++ expect(globalSetupLogic.values.highlight).toBeNull()+ })++ // Staying put must not drop the highlight - a query string change is still the same page.+ it('keeps a pending highlight while the route stays the same', async () => {+ await expectLogic(logic, () => logic.actions.runTask(SetupTaskId.CreateFirstInsight)).toFinishAllListeners()++ router.actions.push(router.values.location.pathname, { tab: 'yours' })++ expect(globalSetupLogic.values.highlight).not.toBeNull()+ })++ // A task with no target selector used to leave the previous pulse polling, because nothing+ // cleared it and a docs task never changes the route.+ it('drops a pending highlight when a task without a target selector runs', async () => {+ jest.spyOn(window, 'open').mockReturnValue(null)+ await expectLogic(logic, () => logic.actions.runTask(SetupTaskId.CreateFirstInsight)).toFinishAllListeners()+ expect(globalSetupLogic.values.highlight).not.toBeNull()++ await expectLogic(logic, () => logic.actions.runTask(SetupTaskId.UsePosthogMcp)).toFinishAllListeners()++ expect(globalSetupLogic.values.highlight).toBeNull()+ })+// A skipped dependency counts as satisfied — skipping used to leave dependents locked forever.it('treats a skipped dependency as satisfied', async () => {await setTeam({diff --git a/frontend/src/lib/components/ProductSetup/productSetupLogic.ts b/frontend/src/lib/components/ProductSetup/productSetupLogic.tsindex 1412b928e57b..2d5208e0f551 100644--- a/frontend/src/lib/components/ProductSetup/productSetupLogic.ts+++ b/frontend/src/lib/components/ProductSetup/productSetupLogic.ts@@ -53,6 +53,9 @@ export interface productSetupLogicValues {// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface productSetupLogicActions {+ clearHighlight: () => {+ value: true+ } // globalSetupLogiccloseGlobalSetup: () => {value: true} // globalSetupLogic@@ -65,8 +68,12 @@ export interface productSetupLogicActions {openGlobalSetup: () => {value: true} // globalSetupLogic- setHighlightSelector: (selector: string | null) => {- selector: string | null+ setHighlight: (+ selector: string,+ pathname: string+ ) => {+ pathname: string+ selector: string} // globalSetupLogicunmarkTaskAsCompleted: (taskIdOrIds: SetupTaskId | SetupTaskId[]) => {taskIdOrIds: AvailableSetupTaskIdsEnumApi | AvailableSetupTaskIdsEnumApi[]@@ -185,7 +192,8 @@ export const productSetupLogic = kea<productSetupLogicType>(['unmarkTaskAsCompleted','markTaskAsSkipped','unmarkTaskAsSkipped',- 'setHighlightSelector',+ 'setHighlight',+ 'clearHighlight',],],})),@@ -365,6 +373,18 @@ export const productSetupLogic = kea<productSetupLogicType>([return}+ posthog.capture('product setup task run', {+ product: props.productKey,+ task: taskId,+ task_type: task.taskType,+ destination: task.getUrl ? 'internal' : task.docsUrl ? 'docs' : 'none',+ has_target_selector: !!task.targetSelector,+ })++ // Each run owns the highlight - a task with no selector must not leave the+ // previous one polling+ actions.clearHighlight()+// Special cases that need non-navigation actionsswitch (taskId) {case SetupTaskId.SetUpWebAnalyticsConversionGoals:@@ -379,11 +399,6 @@ export const productSetupLogic = kea<productSetupLogicType>([break}- // Set highlight selector before navigation so it can highlight after page loads (if we even have to navigate)- if (task.targetSelector) {- actions.setHighlightSelector(task.targetSelector)- }-// Use task's getUrl if available, otherwise fall back to docsUrlif (task.getUrl) {// Close modal before internal navigation (keeps the full "Quick start" button visible)@@ -393,6 +408,12 @@ export const productSetupLogic = kea<productSetupLogicType>([// Keep modal open for external docs linkswindow.open(task.docsUrl, '_blank')}++ // Bind the highlight to the route we landed on, so it cannot pulse an element+ // on a page the user goes to later+ if (task.targetSelector) {+ actions.setHighlight(task.targetSelector, router.values.location.pathname)+ }},dismissSetup: () => {posthog.capture('product setup dismissed', {diff --git a/frontend/src/lib/components/ProductSetup/types.ts b/frontend/src/lib/components/ProductSetup/types.tsindex a3a16991d856..f7ebc503e884 100644--- a/frontend/src/lib/components/ProductSetup/types.ts+++ b/frontend/src/lib/components/ProductSetup/types.ts@@ -84,3 +84,11 @@ export interface ProductSetupConfig {*/tasks: SetupTask[]}++/** A pending attention highlight, bound to the route that asked for it */+export interface SetupHighlight {+ /** CSS selector for the element to highlight */+ selector: string+ /** Route the highlight belongs to - the highlight drops when the user leaves it */+ pathname: string+}diff --git a/frontend/src/lib/components/ProductSetup/useSetupHighlight.test.tsx b/frontend/src/lib/components/ProductSetup/useSetupHighlight.test.tsxnew file mode 100644index 000000000000..f978faecdc7d--- /dev/null+++ b/frontend/src/lib/components/ProductSetup/useSetupHighlight.test.tsx@@ -0,0 +1,63 @@+import '@testing-library/jest-dom'++import { act, cleanup, render } from '@testing-library/react'+import { router } from 'kea-router'++import { urls } from 'scenes/urls'++import { initKeaTests } from '~/test/init'++import { globalSetupLogic } from './globalSetupLogic'+import { useSetupHighlight } from './useSetupHighlight'++describe('useSetupHighlight', () => {+ const SELECTOR = '[data-attr="quick-start-target"]'+ const PULSE_CLASS = 'setup-highlight-pulse'++ beforeEach(() => {+ initKeaTests()+ jest.useFakeTimers()+ render(<HighlightHost />)+ })++ afterEach(() => {+ cleanup()+ jest.useRealTimers()+ document.body.innerHTML = ''+ })++ function HighlightHost(): JSX.Element {+ useSetupHighlight()+ return <div />+ }++ const addTarget = (): HTMLElement => {+ const element = document.createElement('button')+ element.setAttribute('data-attr', 'quick-start-target')+ document.body.append(element)+ return element+ }++ it('pulses the target on the route that asked for it', () => {+ const target = addTarget()++ act(() => globalSetupLogic.actions.setHighlight(SELECTOR, router.values.location.pathname))+ act(() => void jest.advanceTimersByTime(400))++ expect(target).toHaveClass(PULSE_CLASS)+ })++ // The reported bug: the poll outlived its route, so it pulsed the first matching element on+ // whatever page the user opened next. Many task selectors only match deeper inside an entity,+ // which is why the poll so often had nothing to match on the page it was meant for.+ it('does not pulse a matching element on a page opened later', () => {+ act(() => globalSetupLogic.actions.setHighlight(SELECTOR, urls.featureFlag('new')))+ act(() => void jest.advanceTimersByTime(400))++ act(() => router.actions.push(urls.insights()))+ const lateTarget = addTarget()+ act(() => void jest.advanceTimersByTime(2000))++ expect(lateTarget).not.toHaveClass(PULSE_CLASS)+ })+})diff --git a/frontend/src/lib/components/ProductSetup/useSetupHighlight.ts b/frontend/src/lib/components/ProductSetup/useSetupHighlight.tsindex 5b56f9120573..338a415a5a4a 100644--- a/frontend/src/lib/components/ProductSetup/useSetupHighlight.ts+++ b/frontend/src/lib/components/ProductSetup/useSetupHighlight.ts@@ -75,15 +75,17 @@ function scrollIntoViewWithinContainer(element: Element): void {}/**- * Hook that watches for a pending highlight selector and applies a pulsing- * animation to the matching element. Used to draw attention to UI elements- * after navigating from the quick start guide.+ * Hook that watches for a pending highlight and applies a pulsing animation to the+ * matching element. Used to draw attention to UI elements after navigating from the+ * quick start guide. The highlight only applies on the route that asked for it -+ * globalSetupLogic drops it when the user goes somewhere else.** Usage: Call this hook once in a top-level component (e.g., App or Layout).*/export function useSetupHighlight(): void {- const { highlightSelector } = useValues(globalSetupLogic)- const { clearHighlightSelector } = useActions(globalSetupLogic)+ const { highlight } = useValues(globalSetupLogic)+ const { clearHighlight } = useActions(globalSetupLogic)+ const highlightSelector = highlight?.selector ?? nullconst attemptCountRef = useRef(0)const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)const highlightedElementRef = useRef<Element | null>(null)@@ -110,7 +112,7 @@ export function useSetupHighlight(): void {timeoutRef.current = setTimeout(() => {element.classList.remove(HIGHLIGHT_CLASS)highlightedElementRef.current = null- clearHighlightSelector()+ clearHighlight()}, HIGHLIGHT_DURATION_MS)} else if (attemptCountRef.current < MAX_ATTEMPTS) {// Element not found yet - retry (it might still be rendering)@@ -118,7 +120,7 @@ export function useSetupHighlight(): void {timeoutRef.current = setTimeout(tryHighlight, ATTEMPT_INTERVAL_MS)} else {// Give up after max attempts- clearHighlightSelector()+ clearHighlight()}}@@ -135,5 +137,5 @@ export function useSetupHighlight(): void {highlightedElementRef.current = null}}- }, [highlightSelector, clearHighlightSelector])+ }, [highlightSelector, clearHighlight])}