: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
feat(customer-analytics): cache account tab data across tab switches (#66067)
Arthur Moreira de Deus1d4b38870e22
diff --git a/products/customer_analytics/frontend/components/Accounts/AGENTS.md b/products/customer_analytics/frontend/components/Accounts/AGENTS.mdindex 0931ccb89158..06ce3c7d8a8e 100644--- a/products/customer_analytics/frontend/components/Accounts/AGENTS.md+++ b/products/customer_analytics/frontend/components/Accounts/AGENTS.md@@ -58,6 +58,8 @@ Sort safety: removing the sorted column drops the sort (`clearSortIfColumnRemove`AccountsHogQLTable.useExpandable()` makes expansion **controlled** by `accountsExpansionLogic`: `isRowExpanded` reads `expandedAccountIds`, `onRowExpand`/`onRowCollapse` dispatch `toggleAccountExpanded`. The body is `AccountNotebooksExpansion`, a `LemonTabs` over `notes` / `users` / `usage` (`AccountExpansionTab`) plus the Useful links sidebar. Active tab comes from `activeTabFor(accountId)` (defaults to `notes`).+**Tab data is cached for the row's expanded lifetime, not refetched per tab switch.** `LemonTabs` only renders the active tab's content (keyed by `activeKey`), so a tab's logic would normally unmount the moment you switch away and refetch on return. To avoid that, `AccountNotebooksExpansion` holds a mount reference to each per-tab logic via `useMountedLogic` — `accountRelatedUsersLogic({ externalId })` and `accountBillingLogic` for both `kind: 'usage'` and `kind: 'spend'`. Since `AccountNotebooksExpansion` stays mounted for as long as the row is expanded (it's the `expandedRowRender` body), those keyed instances — and their loaded data — survive tab switches and only tear down when the row collapses. The `useMountedLogic` props must stay identical to the `useValues` props in the tab components (`AccountRelatedUsersExpansion`, `AccountBillingExpansion`) so both resolve to the same keyed instance. `accountNotebooksLogic` and `accountLinksLogic` already mount at this level (Notes content and the always-rendered sidebar), so they need no explicit mount reference. Data is loaded once on mount and not auto-refreshed while the row stays open — acceptable since this data needn't be live.+The Usage tab renders an existing saved billing-usage insight — **point users to it, don't rebuild usage as a new insight.**Clicking a note in the Notes tab opens it in the global notebook **side panel** (`notebookPanelLogic.selectNotebook`), keeping the Accounts list mounted — not the full `NotebookScene`. The note `<Link>` still points at `urls.notebook(shortId)` so cmd/ctrl-click opens the full page in a new tab; a plain click `preventDefault()`s the router push and opens the panel instead.diff --git a/products/customer_analytics/frontend/components/Accounts/AccountNotebooksExpansion.tsx b/products/customer_analytics/frontend/components/Accounts/AccountNotebooksExpansion.tsxindex f2ef551f6b04..5e68953cc024 100644--- a/products/customer_analytics/frontend/components/Accounts/AccountNotebooksExpansion.tsx+++ b/products/customer_analytics/frontend/components/Accounts/AccountNotebooksExpansion.tsx@@ -1,4 +1,4 @@-import { useActions, useValues } from 'kea'+import { useActions, useMountedLogic, useValues } from 'kea'import posthog from 'posthog-js'import { IconCloud, IconGraph, IconPencil, IconPeople, IconPiggyBank, IconReceipt } from '@posthog/icons'@@ -22,9 +22,11 @@ import { urls } from 'scenes/urls'import type { AccountNotebookApi } from 'products/customer_analytics/frontend/generated/api.schemas'import { AccountBillingExpansion } from './AccountBillingExpansion'+import { accountBillingLogic } from './accountBillingLogic'import { accountLinksLogic } from './accountLinksLogic'import { accountNotebooksLogic } from './accountNotebooksLogic'import { AccountRelatedUsersExpansion } from './AccountRelatedUsersExpansion'+import { accountRelatedUsersLogic } from './accountRelatedUsersLogic'import { accountsExpansionLogic } from './accountsExpansionLogic'import { AccountsEvents } from './constants'import { EditAccountLinksButton } from './EditAccountLinksButton'@@ -99,6 +101,11 @@ export function AccountNotebooksExpansion({const logic = accountNotebooksLogic({ accountId })const { notebooks, notebooksResponseLoading, createdNoteLoading, searchTerm, sorting, pagination } =useValues(logic)++ // LemonTabs only renders the active tab, so without this the data refetches on every tab switch.+ useMountedLogic(accountRelatedUsersLogic({ externalId }))+ useMountedLogic(accountBillingLogic({ accountId, externalId, kind: 'usage' }))+ useMountedLogic(accountBillingLogic({ accountId, externalId, kind: 'spend' }))const { setSearchTerm, setSorting, createNote } = useActions(logic)const { activeTabFor } = useValues(accountsExpansionLogic)const { setActiveTab } = useActions(accountsExpansionLogic)