: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(customer-analytics): preserve account tab while paging (#83807)
Arthur Moreira de Deuse3c1734d643a
diff --git a/frontend/src/lib/lemon-ui/PaginationControl/types.ts b/frontend/src/lib/lemon-ui/PaginationControl/types.tsindex e4f9db53f79a..6426d41d12b9 100644--- a/frontend/src/lib/lemon-ui/PaginationControl/types.ts+++ b/frontend/src/lib/lemon-ui/PaginationControl/types.ts@@ -1,6 +1,8 @@export interface PaginationBase {/** By default pagination is only shown when there are multiple pages, but will always be if this is `false`. */hideOnSinglePage?: boolean+ /** Set to false when page changes must stay local instead of adding a `page` search parameter to the URL. */+ useUrl?: boolean}export interface PaginationAuto extends PaginationBase {@@ -21,12 +23,6 @@ export interface PaginationManual extends PaginationBase {onForward?: () => void/** Previous page navigation handler. */onBackward?: () => void- /**- * Set to false to stop page changes from being pushed to the URL as a `page` search param.- * Only for tables whose page state lives entirely in their own logic: handler-less controlled- * tables navigate exclusively through that URL param, so they must keep the default.- */- useUrl?: boolean}export type PaginationState<T> = {diff --git a/frontend/src/lib/lemon-ui/PaginationControl/usePagination.test.ts b/frontend/src/lib/lemon-ui/PaginationControl/usePagination.test.tsindex cbe2fb006bba..a35f6e0595ff 100644--- a/frontend/src/lib/lemon-ui/PaginationControl/usePagination.test.ts+++ b/frontend/src/lib/lemon-ui/PaginationControl/usePagination.test.ts@@ -28,4 +28,14 @@ describe('usePagination', () => {act(() => result.current.setCurrentPage(2))expect(router.values.searchParams.page).toBeUndefined()})++ it('paginates local data without changing the URL when useUrl is false', () => {+ const { result } = renderHook(() => usePagination(DATA, { pageSize: 1, useUrl: false }))++ expect(result.current.dataSourcePage).toEqual(['a'])+ act(() => result.current.setCurrentPage(2))++ expect(result.current.dataSourcePage).toEqual(['b'])+ expect(router.values.searchParams.page).toBeUndefined()+ })})diff --git a/frontend/src/lib/lemon-ui/PaginationControl/usePagination.ts b/frontend/src/lib/lemon-ui/PaginationControl/usePagination.tsindex 37f9f4c1fbbe..0346dd4ad9e2 100644--- a/frontend/src/lib/lemon-ui/PaginationControl/usePagination.ts+++ b/frontend/src/lib/lemon-ui/PaginationControl/usePagination.ts@@ -1,6 +1,6 @@import { useActions, useValues } from 'kea'import { router } from 'kea-router'-import { useCallback, useMemo } from 'react'+import { useCallback, useMemo, useState } from 'react'import { PaginationAuto, PaginationManual, PaginationState } from './types'@@ -14,12 +14,15 @@ export function usePagination<T>(const { location, searchParams, hashParams } = useValues(router)const { push } = useActions(router)+ const [localCurrentPage, setLocalCurrentPage] = useState(1)- const syncPageToUrl = !(pagination?.controlled && pagination.useUrl === false)+ const syncPageToUrl = pagination?.useUrl !== falseconst setCurrentPage = useCallback((newPage: number) => {if (syncPageToUrl) {push(location.pathname, { ...searchParams, [currentPageParam]: newPage }, hashParams)+ } else {+ setLocalCurrentPage(newPage)}},[location, searchParams, hashParams, push, syncPageToUrl] // oxlint-disable-line react-hooks/exhaustive-deps@@ -30,7 +33,10 @@ export function usePagination<T>(entryCount && (pagination ? (pagination.pageSize ? Math.ceil(entryCount / pagination.pageSize) : 1) : null)const currentPage: number | null = pagination?.controlled? pagination.currentPage || null- : Math.min(parseInt(searchParams[currentPageParam]) || 1, pageCount as number)+ : Math.min(+ syncPageToUrl ? parseInt(searchParams[currentPageParam]) || 1 : localCurrentPage,+ pageCount as number+ )const { dataSourcePage, currentStartIndex, currentEndIndex } = useMemo(() => {const calculatedStartIndex =diff --git a/products/customer_analytics/frontend/components/Accounts/AGENTS.md b/products/customer_analytics/frontend/components/Accounts/AGENTS.mdindex eaeb56eebb2b..d92685bd81bf 100644--- a/products/customer_analytics/frontend/components/Accounts/AGENTS.md+++ b/products/customer_analytics/frontend/components/Accounts/AGENTS.md@@ -110,7 +110,7 @@ Sort safety: removing the sorted column drops the sort (`clearSortIfColumnRemove## The expanded row-`AccountsTable.useExpandable()` makes expansion **controlled** by `accountsExpansionLogic`: `isRowExpanded` reads `expandedAccountIds`, `onRowExpand`/`onRowCollapse` dispatch `toggleAccountExpanded`. The body is `AccountNotebooksExpansion`, a `LemonTabs` over `notes` / `users` / `relationships` / `usage` / `spend` / `opportunities` / `summaries` / `support_tickets` / `email_threads` / `meetings` / `event_stream` (`AccountExpansionTab`; the `event_stream` tab is gated by the `CUSTOMER_ANALYTICS_CSP` flag) plus the sidebar (Useful links + an active-relationships summary, `ActiveRelationships`, hidden when nothing is assigned). Active tab comes from `activeTabFor(accountId)` (defaults to `notes`).+`AccountsTable.useExpandable()` makes expansion **controlled** by `accountsExpansionLogic`: `isRowExpanded` reads `expandedAccountIds`, `onRowExpand`/`onRowCollapse` dispatch `toggleAccountExpanded`. The body is `AccountNotebooksExpansion`, a `LemonTabs` over `notes` / `users` / `relationships` / `usage` / `spend` / `opportunities` / `summaries` / `support_tickets` / `email_threads` / `meetings` / `event_stream` (`AccountExpansionTab`; the `event_stream` tab is gated by the `CUSTOMER_ANALYTICS_CSP` flag) plus the sidebar (Useful links + an active-relationships summary, `ActiveRelationships`, hidden when nothing is assigned). Active tab comes from `activeTabFor(accountId)` (defaults to `notes`). Pagination inside these tabs keeps its page state out of the URL so changing pages does not rerun deep-link restoration and replace the active tab.**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 })`, `accountRelationshipsLogic({ accountId })`, `accountBillingLogic` for both `kind: 'usage'` and `kind: 'spend'`, `accountOpportunitiesLogic({ accountId })`, `accountSummariesLogic({ accountId })`, `accountSupportTicketsLogic({ accountId })`, `accountEmailThreadsLogic({ accountId })`, and `accountMeetingsLogic({ accountId })`. Since `AccountNotebooksExpansion` stays mounted for as long as the row is expanded (it's the `expandedRowRender` body), those keyed instances 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`, `AccountRelationshipsExpansion`, `AccountBillingExpansion`, `AccountOpportunitiesExpansion`, `AccountSummariesExpansion`, `AccountSupportTicketsExpansion`, `AccountEmailThreadsExpansion`, `AccountMeetingsExpansion`) 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.diff --git a/products/customer_analytics/frontend/components/Accounts/AccountEmailThreadsExpansion.tsx b/products/customer_analytics/frontend/components/Accounts/AccountEmailThreadsExpansion.tsxindex 8dbf3689cef9..906eae52583a 100644--- a/products/customer_analytics/frontend/components/Accounts/AccountEmailThreadsExpansion.tsx+++ b/products/customer_analytics/frontend/components/Accounts/AccountEmailThreadsExpansion.tsx@@ -207,6 +207,7 @@ export function AccountEmailThreadsExpansion({ accountId }: { accountId: stringcontrolled: true,pageSize: PAGE_SIZE,currentPage: page,+ useUrl: false,entryCount: count,onForward: () => setPage(page + 1),onBackward: () => setPage(page - 1),diff --git a/products/customer_analytics/frontend/components/Accounts/AccountMeetingsExpansion.tsx b/products/customer_analytics/frontend/components/Accounts/AccountMeetingsExpansion.tsxindex 0886176ab4e3..dfe276446fab 100644--- a/products/customer_analytics/frontend/components/Accounts/AccountMeetingsExpansion.tsx+++ b/products/customer_analytics/frontend/components/Accounts/AccountMeetingsExpansion.tsx@@ -231,6 +231,7 @@ export function AccountMeetingsExpansion({ accountId }: { accountId: string }):controlled: true,pageSize: PAGE_SIZE,currentPage: page,+ useUrl: false,entryCount: count,onForward: () => setPage(page + 1),onBackward: () => setPage(page - 1),diff --git a/products/customer_analytics/frontend/components/Accounts/AccountRelatedUsersExpansion.tsx b/products/customer_analytics/frontend/components/Accounts/AccountRelatedUsersExpansion.tsxindex bf1e26ff953d..0d9b30684140 100644--- a/products/customer_analytics/frontend/components/Accounts/AccountRelatedUsersExpansion.tsx+++ b/products/customer_analytics/frontend/components/Accounts/AccountRelatedUsersExpansion.tsx@@ -52,6 +52,7 @@ export function AccountRelatedUsersExpansion({ externalId }: { externalId: strincontrolled: true,pageSize: PAGE_SIZE,currentPage: page,+ useUrl: false,entryCount: membersResponse?.count ?? 0,onForward: () => setPage(page + 1),onBackward: () => setPage(page - 1),diff --git a/products/customer_analytics/frontend/components/Accounts/AccountRelationshipsExpansion.tsx b/products/customer_analytics/frontend/components/Accounts/AccountRelationshipsExpansion.tsxindex 7ccec8ae436a..4fbd974be1c4 100644--- a/products/customer_analytics/frontend/components/Accounts/AccountRelationshipsExpansion.tsx+++ b/products/customer_analytics/frontend/components/Accounts/AccountRelationshipsExpansion.tsx@@ -140,7 +140,7 @@ export function AccountRelationshipsExpansion({ accountId }: { accountId: stringrowKey="id"loading={relationshipsLoading}columns={columns}- pagination={{ pageSize: PAGE_SIZE }}+ pagination={{ pageSize: PAGE_SIZE, useUrl: false }}emptyState={relationships === null ? 'Failed to load relationships.' : 'No assignments on this account yet.'}diff --git a/products/customer_analytics/frontend/components/Accounts/AccountSupportTicketsExpansion.tsx b/products/customer_analytics/frontend/components/Accounts/AccountSupportTicketsExpansion.tsxindex 6bba703a03f1..17b568feebba 100644--- a/products/customer_analytics/frontend/components/Accounts/AccountSupportTicketsExpansion.tsx+++ b/products/customer_analytics/frontend/components/Accounts/AccountSupportTicketsExpansion.tsx@@ -102,7 +102,7 @@ export function AccountSupportTicketsExpansion({ accountId }: { accountId: strindataSource={tickets}columns={columns}rowKey="id"- pagination={{ pageSize: PAGE_SIZE }}+ pagination={{ pageSize: PAGE_SIZE, useUrl: false }}/>)}diff --git a/products/customer_analytics/frontend/components/Accounts/accountNotebooksLogic.ts b/products/customer_analytics/frontend/components/Accounts/accountNotebooksLogic.tsindex 0af49d11f4db..6f398369d159 100644--- a/products/customer_analytics/frontend/components/Accounts/accountNotebooksLogic.ts+++ b/products/customer_analytics/frontend/components/Accounts/accountNotebooksLogic.ts@@ -220,6 +220,7 @@ export const accountNotebooksLogic = kea<accountNotebooksLogicType>([controlled: true,pageSize: NOTES_PER_PAGE,currentPage: page,+ useUrl: false,entryCount: count,onBackward: () => actions.setPage(page - 1),onForward: () => actions.setPage(page + 1),