: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(phai): virtualize tasks list with infinite-scroll pagination (#66810)
Georgiy Tarasov722d1a548944
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 25935b29b23e..23c4fc40df40 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -6757,57 +6757,57 @@ snapshots:scenes-app-tasks--list-load-error--light:hash: v1.k794b7964.2de00f8e595c5a4ebb95b4a4d1df7b4cfe0758a2e306aec06428e885a887fb33.9Lw90ITaMIS8RDteHiEsYena4Qf0TVo8s7bR0mmfJgkscenes-app-tasks--list-with-composer--dark:- hash: v1.k794b7964.8086819e49ade5d2ccae636ebce34b49608527bcd863a4ef324a804b6ed8398b.O-zGS78n9tRnqnwpsqFb3lu_1X-iywqHvaln34O2A8k+ hash: v1.k794b7964.bf8b6abf4b61c5a5a753a4a4b65a68a826083843c72ce5c84874a5f8b1a351f0.8_E1dRIEkR4aBflwi38DbZ24Bb-O8JlxNhV7r0ftFCMscenes-app-tasks--list-with-composer--light:- hash: v1.k794b7964.8ab1a195143a6c511dc6e9486d88230c9f24b24019c36fc887c7fdafb59a8286._MrwcL0ak6gAhwa6mkeD4pAJBDPxId_xCapLrxVQ2xo+ hash: v1.k794b7964.645d8fb5c766ad02d84cde4622a5bbe7234addd10bcc9ee7c228cd522fc44527.LY9de-ZX-ogFSxm5PbmeU4XHXNOlvoXQoxXCHUqszVMscenes-app-tasks--loading--dark:hash: v1.k794b7964.32b705cea8e08c33e6ef4674ea857dfc27b541a2fee2d232fec23a811166c3a5.644_lPpowbUxRspP7g_5grEdTDVLLSl8QxXUfKsttBsscenes-app-tasks--loading--light:hash: v1.k794b7964.6b5ef9b2b816678bf318eb6d88597e8a28a2e5b53a1a0be1e60da085038440ad.PVA4aALLY3uzsw8P7IC0bM41u9SfU18yljEFMPtLFqwscenes-app-tasks--mobile-list--dark:- hash: v1.k794b7964.9b1437f6ceb5ad8c5d83758f88388cddfafe1a6d56805697d09f09ce86d44f8f.Rq0kp9NZJu3ednwVL5gXm5U521aaSYQ42Wxfpza1gTE+ hash: v1.k794b7964.e65c5e289cbb347ed1cc035d3a381c56503b67ef643db47dd2e02f32fac047a8.aNQOxj2nwQyFuzC8E3a1YGPFtaxje7hw1Eb7HbBLyfQscenes-app-tasks--mobile-list--light:- hash: v1.k794b7964.a220154ffeddd74c8e1c79537b3dbe134cc92fa824c09afa6c57d5658588df27.duyTBLlJtT6EM9_hlD8iKM4VuSvM-8M12i9fGUm32WI+ hash: v1.k794b7964.a42e7297c99d46bf03e8ba9c7576b164e120a41c914d1d52824823140b8fae92.nCFkmftkVPQYI7UqGBF84D6YQ52LTeSiWkz6w_K_YWMscenes-app-tasks--mobile-new-task--dark:hash: v1.k794b7964.de22e10e282dd787afc1fc4784d1aef6064b32b7c3bed6b3bced8ba776264cf2.UCqKfpWcRlmvwmvML2DjdyVQCwj3zUZpXlKA8wxMgVsscenes-app-tasks--mobile-new-task--light:hash: v1.k794b7964.cf669044c3c0e2b6d870e588a22f58be3032bec6d90a2c1c3b1ee1412a491661.3mNJ_P0G8pSfhi3oEkjsTKKG7wVSFB9jdY7ujjDXj7kscenes-app-tasks--mobile-task-selected--dark:- hash: v1.k794b7964.45c56cdba57d4cdfcca851cc2ad88c08831fe0cbab19863b86a028705d7b52a8.BwQ4BP5IbXOFCimc4-sLUVE54-zEA9naxwb7q7EWR58+ hash: v1.k794b7964.7a885468ce6eee10b0835ef0b76f5c5dd45d35d90273d972bcb8023d9c943b62.4O4SeGjvj3rHSH0F5LinWCoJv7oGd0UgG39TRxQQeEoscenes-app-tasks--mobile-task-selected--light:- hash: v1.k794b7964.fcba0f8e9e7360da3c671debfff263fc22467c9820e5706207523add08e29d99.Nr7dbzdN-8LSM4JvLEOty1cjbb4zz4XFhGfJp9pH8iQ+ hash: v1.k794b7964.00797fdb57fa653b857ff7fdf25637a36d62cb154d37cecee705687ef02b17d3.M87ub65d6ey1Ny2hpCl6o-NLyohPeBZFZ6Mg7BmEIsoscenes-app-tasks--new-task--dark:- hash: v1.k794b7964.8086819e49ade5d2ccae636ebce34b49608527bcd863a4ef324a804b6ed8398b.DrdmADuL7hC5Rf2b3OEE2FNg5bHUqRjf1H9IKpsnsTk+ hash: v1.k794b7964.bf8b6abf4b61c5a5a753a4a4b65a68a826083843c72ce5c84874a5f8b1a351f0.4_xbfeooSsTCGwEbJXXSsU9vEwOIJ51xCba_zMO0sL8scenes-app-tasks--new-task--light:- hash: v1.k794b7964.8ab1a195143a6c511dc6e9486d88230c9f24b24019c36fc887c7fdafb59a8286.Nfq6WiiUSd4EOik89MwawQHvkYP-zNjoIPC338iroS8+ hash: v1.k794b7964.645d8fb5c766ad02d84cde4622a5bbe7234addd10bcc9ee7c228cd522fc44527.fZHCwOXXgxl4XaSatDo2KaYmaFJ4cYUkRcsr2yOyPUEscenes-app-tasks--new-task-with-repository--dark:- hash: v1.k794b7964.caa8962e73b4e377d223d5052766653822bebc7fdef88de4565671b8766afad7.ZiQGQ2eJ3EsUJrIM64QFNcu6oPeTY5v-qiWNgYGneLI+ hash: v1.k794b7964.0b91a374f31195a572e4dc9ba06538fb24aa469715053646c59d6dcf55ce9d0a.mPiBMxgeYR2VFvWiyCVIqAffHpa1eWlmq1j6CelnInMscenes-app-tasks--new-task-with-repository--light:- hash: v1.k794b7964.1287c1759d562b8ad2204c9a67e7bdb54b22ee66768ba7841546fd60b4bfb469.e9Um6800oekpBDYMqI0aIR5d9sPlVnUlHiSFDtLrYGw+ hash: v1.k794b7964.5e2f1107fe1ffce2d4c0189c839624e05c0c5df50011769bac86eb17e9476422.EUn4T_Fj1IbtANyMVPjdzJiKLWfZmI4Yoz2bnzPVdhUscenes-app-tasks--task-detail-loading--dark:- hash: v1.k794b7964.7157fdb1929c65c3c11e54e0ee8731a74666cfae0ba2b581e2c4befe639b4eaa.RwNC56JcBC5-5F4kRABDSIkG9EJOiHLbW5ajkOM7AVg+ hash: v1.k794b7964.a05d0af03f7eaeb33e1c22ccae2d417241ef3cb997cb4675ac5f8efe701a7c74.Fn6G0_Zzcycs9ikkn7R1jXhXk0czUQGbcdU0X58F8Joscenes-app-tasks--task-detail-loading--light:- hash: v1.k794b7964.13cc3bd705ad0db7e1b113b6ff67c633949610307e63b6270d6344c55ae47c9e.zMA65-NvFFMFZ8Et9QD-J983FxzPKLkdw3ICd1enD7E+ hash: v1.k794b7964.a455c6ce87abbb0be5bae6e013455678166db05ade23e9fed901b92dac926d47.XEL007g9N3b7_FZJSRFjvf0rPdAt5R93_T08JWg9zwQscenes-app-tasks--task-load-error--dark:- hash: v1.k794b7964.cdc2e0441654b6086e1ce67142d3c10b88f3179541eb07f357f308a0f0027a6b.ActBAl1pchpBKKJDqgDKuyoa7ViCrW5TqwrIzSPy0pM+ hash: v1.k794b7964.f3d65528db5a43c89cbe9bf66ec9e313db499df7045ba0bf521104ddbca900d2.h1dLTgPlrckaLgR-hD2xaGZThKQ_zyksj9s8No_fsEkscenes-app-tasks--task-load-error--light:- hash: v1.k794b7964.0b2e77362d7bf4a4e26ed24cf6fbe0a7ba5795f82c90ff3a2f70b7cd1cf63d9a._N0lKcnpzgF57TFrUaXJz5DwMV2hjLgMDBiK7d6vjro+ hash: v1.k794b7964.408fcd86353d25498abb81ae3e6dd494e0c03ba3d32cd1ba4aee8faa4598f00a._0cj5yk1CfiCa6nLd8gAOqWBAlWX-TyxFH7hqJ-mP6kscenes-app-tasks--task-not-found--dark:- hash: v1.k794b7964.b08c928357e664fe33e981dba1423ae1455d8f4c6492027a1f12adc78b6adbbb.j1sCeRMKe0G44snGBxJyZKCHrjP_S4RZETX9YQovATM+ hash: v1.k794b7964.38142fe7f1c98f077ebae7d70c621fc21cea3f3336a17746d44204fac7e2fe9f.tEi4TamNvzQ1wDB2CBJUIKzgudNsEgoljUYQlh5AY60scenes-app-tasks--task-not-found--light:- hash: v1.k794b7964.c6e505de08d55f26e1c3c47aa85b972772d188b7fe68759eb0d9cb8eb9406679.EHNR2eQ9-l5xVHSV-PZb7FdPbpsC4i44DzUDj1MF6wk+ hash: v1.k794b7964.f1b65c06dd37c93f4938e24ba2670e80cb744a1accede5bb503de89440f43363.VugviXEES0WiBa642XckMwc9IiBpXQ6oRlhyz_sJWqMscenes-app-tasks--task-run-not-found--dark:- hash: v1.k794b7964.10ec81cd4b77f4d5450bd626d94854c347aad78e574ab41c75c64c3edb96d0ed.vqsdv6YyglvAsN__IPttRHp7hRtyx4IoGn4auQ4WUxw+ hash: v1.k794b7964.8e8840b1ecf8ff0e3fd6b718da4d9c4784db4900a746ef84caafbb55e387f32a.C2mnIggGT3uYfoBXlw1MjryWm9HS-BB251L3UXfQfeQscenes-app-tasks--task-run-not-found--light:- hash: v1.k794b7964.b23e37e271df13dc0c1030c46cd6a242f455871b233fdd66b1bee26ac012ce20.QeDtgkEfHGhfe-D3MZnLrcK-RhE6wtB1YicLdf-bmTY+ hash: v1.k794b7964.d5dd75a113661dd6b5de8cad1b4fe35961a8eeec472a239eda97cc2d34167a63.w3uvwt0wsBOY6P5SRUj-1gn66H9bxVBXeNGyDPvF_6oscenes-app-tasks--task-runs-load-error--dark:- hash: v1.k794b7964.837ac84283070e20a19f9b9094f384cb412f1b533a5b8745fcb671539519e7a5.E8g9hLTcNjUNs7vXrfRnh9bGYcFieJppRc-fxDqNVvs+ hash: v1.k794b7964.360d321e0c84b7ab7e34612bd4aad3b2158326c782368fcf1a864f3b19c43755.DtboQZKjL7v6xasUWALtVxG55nhxrBQrv7KOR8SJzNkscenes-app-tasks--task-runs-load-error--light:- hash: v1.k794b7964.d99161cc6ec4ec0b97ad11671591e03e58a694ffe1b07e8065ab9030f898f928.RagHhf2mBEWJlXxrnvLMuoaSmEmy4Z5N3MkiYuiChOc+ hash: v1.k794b7964.634848c1a193aab289c469885d1b78ae21f29a75c7e82e529577cd6dd5e4d316.yzwfmNlDKsXTdIpohIsZiom-BFLHE0pL5s9atup4eVAscenes-app-tasks--task-selected--dark:- hash: v1.k794b7964.d5432700c07983bb314f0f30593b7829752fa26c903a07fc6803733f9b47bd87.7uDDWFLn_NELzc6jE4sJhZ8yCuIk70g8tbKiQPrGsxM+ hash: v1.k794b7964.019c21cea37dd70f5155463c26895ec38459601d1f56212b29953e1506e9893f.pBgakE1PTz8mQ9LQwEfUORcYgaAitvAef8ZUngtn178scenes-app-tasks--task-selected--light:- hash: v1.k794b7964.a94034a37b78a81a23ccd110f526389adb01e1a63ef7150fbf05b8859e98d9d5.tWMNpbKSLF2yMN4WZ6eJ9ZTvhGtDbhEvuMoBhig5e3c+ hash: v1.k794b7964.fd53359c2d495f95cfd065fe5e728cbb9cab9f027df4aea3963570674206bad9.t9wE5rwpZI_f85AkQ8WYWRoEHuO_hZtsBwTh8_AOwfwscenes-app-user-interviews-invite-preview-modal--emailable--dark:hash: v1.k794b7964.0cd3e50dcd442e57712b0ebe06d6952c589a4c88c49fca26771c9e17bc07e6dc.iNYX9Up5MvnGHGT7ku7yMuFIJ0NnbSspOz6Ce0Kb2cUscenes-app-user-interviews-invite-preview-modal--emailable--light:diff --git a/products/posthog_ai/frontend/logics/tasksLogic.test.ts b/products/posthog_ai/frontend/logics/tasksLogic.test.tsindex f2b5fdef7a77..838ea902b1ea 100644--- a/products/posthog_ai/frontend/logics/tasksLogic.test.ts+++ b/products/posthog_ai/frontend/logics/tasksLogic.test.ts@@ -1,4 +1,6 @@-import { MOCK_DEFAULT_USER } from 'lib/api.mock'+import { MOCK_DEFAULT_USER, api } from 'lib/api.mock'++import { expectLogic } from 'kea-test-utils'import { userLogic } from 'scenes/userLogic'@@ -93,4 +95,42 @@ describe('tasksLogic', () => {})})})++ describe('loadMoreTasks', () => {+ // Regression coverage: `loadMoreTasks` reads `tasksNext` again after its `await`, so a+ // `loadTasks` dispatched while a page is in flight (e.g. a filter change) must not have its+ // state clobbered when the stale page resolves afterwards.+ it('discards a page that resolves after tasksNext has already moved on', async () => {+ const task1 = createMockTask('task-1')+ logic.actions.loadTasksSuccess([task1])+ logic.actions.setTasksNext('/api/projects/1/tasks/?cursor=page-2')++ let resolvePage2: (value: unknown) => void = () => {}+ jest.spyOn(api, 'get').mockImplementationOnce(() => new Promise((resolve) => (resolvePage2 = resolve)))++ logic.actions.loadMoreTasks()+ // A filter change resets the cursor synchronously (via the `loadTasks` reducer) while+ // the page-2 request above is still in flight.+ logic.actions.setTasksNext(null)++ resolvePage2({ results: [createMockTask('stale-page-2-task')], next: null })+ await expectLogic(logic).toFinishAllListeners()++ expect(logic.values.tasks).toEqual([task1])+ expect(logic.values.tasksNext).toBeNull()+ })++ // Regression coverage: without clearing `tasksNext` on failure, `hasMore` stays true forever+ // and the infinite-scroll spinner never goes away after a failed page load.+ it('clears tasksNext on failure so the list stops reporting more pages', async () => {+ logic.actions.setTasksNext('/api/projects/1/tasks/?cursor=page-2')+ jest.spyOn(api, 'get').mockRejectedValueOnce(new Error('network error'))++ logic.actions.loadMoreTasks()+ await expectLogic(logic).toFinishAllListeners()++ expect(logic.values.tasksNext).toBeNull()+ expect(logic.values.tasksLoadingMore).toBe(false)+ })+ })})diff --git a/products/posthog_ai/frontend/logics/tasksLogic.ts b/products/posthog_ai/frontend/logics/tasksLogic.tsindex 61c0d11ab777..7ca588b5aaa2 100644--- a/products/posthog_ai/frontend/logics/tasksLogic.ts+++ b/products/posthog_ai/frontend/logics/tasksLogic.ts@@ -4,7 +4,7 @@ import { router } from 'kea-router'import { lemonToast } from '@posthog/lemon-ui'-import api from 'lib/api'+import api, { PaginatedResponse } from 'lib/api'import { addProductIntent } from 'lib/utils/product-intents'import { userLogic } from 'scenes/userLogic'@@ -26,9 +26,10 @@ export const tasksLogic = kea<tasksLogicType>([updateTask: (task: Task) => ({ task }),setSearchQuery: (search: string) => ({ search }),setAssigneeFilter: (assigneeFilter: TaskAssigneeFilter) => ({ assigneeFilter }),+ setTasksNext: (next: string | null) => ({ next }),}),- loaders(({ values }) => ({+ loaders(({ actions, values }) => ({tasks: [[] as Task[],{@@ -37,8 +38,31 @@ export const tasksLogic = kea<tasksLogicType>([loadTasks: async (params: TaskListParams = {}, breakpoint) => {const response = await api.tasks.list(params)breakpoint()+ actions.setTasksNext(response.next ?? null)return response.results},+ // Appends the next page for infinite scroll. The cursor is the absolute `next`+ // URL from the previous response, so it carries the active filters forward.+ loadMoreTasks: async (_: void, breakpoint) => {+ const next = values.tasksNext+ if (!next) {+ return values.tasks+ }+ // `next` is an opaque absolute cursor URL from the previous response, not a static+ // endpoint — the generated `tasksList` takes structured params, not a raw URL.+ // nosemgrep: prefer-codegen-api+ const response = await api.get<PaginatedResponse<Task>>(next)+ breakpoint()+ // `breakpoint` only cancels a second `loadMoreTasks` call, not a `loadTasks` triggered+ // by a filter change while this page was in flight. A fresh `loadTasks` resets+ // `tasksNext` to null synchronously on dispatch, so a mismatch here means this page+ // belongs to a filter that's no longer active — discard it instead of appending.+ if (values.tasksNext !== next) {+ return values.tasks+ }+ actions.setTasksNext(response.next ?? null)+ return [...values.tasks, ...response.results]+ },createTask: async ({ data }: { data: TaskUpsertProps }) => {const newTask = await api.tasks.create(data)lemonToast.success('Task created successfully')@@ -92,6 +116,28 @@ export const tasksLogic = kea<tasksLogicType>([loadTasksFailure: (_, { error, errorObject }) => loadErrorMessage(error, errorObject),},],+ // Cursor for the next page; null once the list is exhausted. Reset on every fresh load so a+ // filter/search change starts from page one.+ tasksNext: [+ null as string | null,+ {+ loadTasks: () => null,+ setTasksNext: (_, { next }) => next,+ // Clear the cursor on failure too, otherwise `hasMore` stays true forever and the+ // infinite-scroll spinner keeps spinning with no feedback that the request failed.+ loadMoreTasksFailure: () => null,+ },+ ],+ // Distinct from `tasksLoading` (which also flips for `loadMoreTasks`) so the infinite-scroll+ // trigger can guard against firing again while a page is already in flight.+ tasksLoadingMore: [+ false,+ {+ loadMoreTasks: () => true,+ loadMoreTasksSuccess: () => false,+ loadMoreTasksFailure: () => false,+ },+ ],}),selectors({@@ -121,5 +167,8 @@ export const tasksLogic = kea<tasksLogicType>([setAssigneeFilter: () => {actions.loadTasks(values.taskListParams)},+ loadMoreTasksFailure: ({ error, errorObject }) => {+ lemonToast.error(`Couldn't load more tasks: ${loadErrorMessage(error, errorObject)}`)+ },})),])diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/TaskTracker.stories.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/TaskTracker.stories.tsxindex 256a74a6a9e2..e835854dea71 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/TaskTracker.stories.tsx+++ b/products/posthog_ai/frontend/scenes/TaskTracker/TaskTracker.stories.tsx@@ -322,7 +322,7 @@ const MOBILE_PARAMETERS = {testOptions: { viewport: MOBILE_VIEWPORT },}-// Mobile: the list fills the screen and scrolls with the page, with a floating "New task" button.+// Mobile: the list fills the screen in its own scroll container, with a floating "New task" button.export const MobileList: Story = {parameters: MOBILE_PARAMETERS,}diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/TaskTracker.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/TaskTracker.tsxindex 05bdd669d105..a094d7b7a241 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/TaskTracker.tsx+++ b/products/posthog_ai/frontend/scenes/TaskTracker/TaskTracker.tsx@@ -64,9 +64,10 @@ export function TaskTracker({ taskId }: TaskTrackerProps): JSX.Element {</SceneContent>)}- // List view scrolls with the page (main), not an inner container, so no fixed height here.+ // Full-height column so the virtualized list has a bounded height to fill; the header stays+ // fixed and the list owns its own scroll (the page no longer scrolls).return (- <SceneContent>+ <SceneContent className="h-full"><SceneTitleSectionname={sceneConfigurations[Scene.TaskTracker].name}description={sceneConfigurations[Scene.TaskTracker].description}diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskDetailPage.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskDetailPage.tsxindex 8c57baa9326e..3e3dfb1664e3 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskDetailPage.tsx+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskDetailPage.tsx@@ -189,7 +189,7 @@ export function TaskDetailPage({ taskId, isMobile }: TaskDetailPageProps): JSX.EselectedRun && <TaskRunMetadata selectedRun={selectedRun} />)}- <LemonDivider className="mb-0 mt-0 lg:mt-2" />+ <LemonDivider className="hidden lg:block mb-0 mt-2" /></header><TaskRunLog taskId={taskId} />diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskListItem.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskListItem.tsxindex 5129ebb500a5..dd17b259b753 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskListItem.tsx+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskListItem.tsx@@ -1,5 +1,6 @@import { useActions } from 'kea'import { router } from 'kea-router'+import { memo } from 'react'import { IconArchive } from '@posthog/icons'@@ -25,7 +26,15 @@ function compactTimeAgo(iso: string): string {return humanFriendlyDuration(seconds, { maxUnits: 1 })}-export function TaskListItem({ task, isActive }: { task: Task; isActive: boolean }): JSX.Element {+// Memoized: the parent re-renders the whole list on every task projection, but a row only changes+// when its task or active state does.+export const TaskListItem = memo(function TaskListItem({+ task,+ isActive,+}: {+ task: Task+ isActive: boolean+}): JSX.Element {const { deleteTask } = useActions(tasksLogic)const displayTitle = task.title || task.slug@@ -76,4 +85,4 @@ export function TaskListItem({ task, isActive }: { task: Task; isActive: boolean</LinkListItem.Actions></LinkListItem.Root>)-}+})diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/TasksListColumn.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/TasksListColumn.tsxindex 6cafeb26d279..b846bd077f93 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/TasksListColumn.tsx+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/TasksListColumn.tsx@@ -4,27 +4,46 @@ import { IconPlus, IconPlusSmall } from '@posthog/icons'import { LemonBanner, LemonButton, LemonDivider, LemonSkeleton } from '@posthog/lemon-ui'import { Input } from '@posthog/quill-primitives'-import { ScrollableShadows } from 'lib/components/ScrollableShadows/ScrollableShadows'import { Link } from 'lib/lemon-ui/Link'+import { cn } from 'lib/utils/css-classes'import { urls } from 'scenes/urls'import { tasksLogic } from '../../../logics/tasksLogic'import { TaskAssigneeFilterMenu } from './TaskAssigneeFilterMenu'-import { TaskListItem } from './TaskListItem'+import { VirtualizedTasksList } from './VirtualizedTasksList'interface TasksListColumnProps {/** Currently selected task id, used to highlight its row. Null when showing the composer. */selectedTaskId: string | null- /** On mobile the column is the whole screen: the page scrolls and a floating button creates a task. */+ /** On mobile the column is the whole screen: the list scrolls in its own container and a floating button creates a task. */isMobile?: boolean}export function TasksListColumn({ selectedTaskId, isMobile = false }: TasksListColumnProps): JSX.Element {- const { tasks, tasksLoading, tasksError, searchQuery, assigneeFilter, taskListParams } = useValues(tasksLogic)- const { loadTasks, setSearchQuery } = useActions(tasksLogic)+ const {+ tasks,+ tasksLoading,+ tasksError,+ tasksNext,+ tasksLoadingMore,+ searchQuery,+ assigneeFilter,+ taskListParams,+ } = useValues(tasksLogic)+ const { loadTasks, loadMoreTasks, setSearchQuery } = useActions(tasksLogic)- const rows =- tasksLoading && tasks.length === 0 ? (+ // With tasks present the list is virtualized (it fills a bounded-height container); the empty,+ // loading, and error states render as plain blocks since they need no windowing.+ const content =+ tasks.length > 0 ? (+ <VirtualizedTasksList+ tasks={tasks}+ selectedTaskId={selectedTaskId}+ hasMore={!!tasksNext}+ loadingMore={tasksLoadingMore}+ onLoadMore={() => loadMoreTasks()}+ />+ ) : tasksLoading ? (<div className="flex flex-col gap-1 px-1"><LemonSkeleton className="h-8" /><LemonSkeleton className="h-8 opacity-60" />@@ -32,7 +51,7 @@ export function TasksListColumn({ selectedTaskId, isMobile = false }: TasksListC</div>) : // A failed load with no cached tasks must not look like "No tasks yet" — show the error + a retry.// A refresh that fails while tasks already exist keeps the stale list rather than wiping good data.- tasksError && tasks.length === 0 ? (+ tasksError ? (<LemonBannertype="error"className="mx-1"@@ -42,14 +61,12 @@ export function TasksListColumn({ selectedTaskId, isMobile = false }: TasksListC<p className="mb-0">We couldn't load your tasks.</p><p className="text-muted mb-0">{tasksError}</p></LemonBanner>- ) : tasks.length === 0 ? (+ ) : (<div className="flex flex-col items-center justify-center text-center py-8 text-muted"><p className="text-sm mb-0">{searchQuery || assigneeFilter !== 'for_you' ? 'No tasks match your filters' : 'No tasks yet'}</p></div>- ) : (- tasks.map((task) => <TaskListItem key={task.id} task={task} isActive={task.id === selectedTaskId} />))const searchInput = (@@ -67,12 +84,14 @@ export function TasksListColumn({ selectedTaskId, isMobile = false }: TasksListC)if (isMobile) {- // The page (main) scrolls — no inner scroll container. Extra bottom padding keeps the last- // rows clear of the floating create button.+ // The virtualized list owns its own scroll inside this bounded-height column. The trailing+ // spacer ends the list above the floating create button so it never hides the last row.return (- <>- <div className="px-1 pb-2">{searchInput}</div>- <div className="flex flex-col gap-1 pb-24">{rows}</div>+ <div className="flex flex-col flex-1 min-h-0">+ <div className="shrink-0 lg:px-1">{searchInput}</div>+ <LemonDivider className="mb-0 mt-4" />+ <div className={cn('flex flex-col flex-1 min-h-0', tasks.length > 0 && '-mx-4')}>{content}</div>+ <div className="shrink-0 h-20" /><LemonButtontype="primary"icon={<IconPlus />}@@ -83,7 +102,7 @@ export function TasksListColumn({ selectedTaskId, isMobile = false }: TasksListC>New task</LemonButton>- </>+ </div>)}@@ -100,21 +119,11 @@ export function TasksListColumn({ selectedTaskId, isMobile = false }: TasksListC<IconPlusSmall className="size-4" /></Link></div>- <div className="px-1 pb-2 shrink-0">{searchInput}</div>+ <div className="px-1 pb-4 shrink-0">{searchInput}</div><LemonDivider className="m-0 shrink-0" />- <ScrollableShadows- direction="vertical"- className="flex flex-col flex-1 min-h-0 overflow-hidden pt-2"- innerClassName="pr-2"- // Row gap + trailing space live on the content, not the scroll viewport: a single- // Content child means a gap on the viewport is a no-op, and Chrome drops a scroll- // container's `padding-bottom`, so `pb-4` only sticks here.- contentClassName="flex flex-col gap-1 pb-4"- styledScrollbars- >- {rows}- </ScrollableShadows>+ {/* flex-1 min-h-0 gives the virtualized list a bounded height to fill (it owns the scroll). */}+ <div className="flex flex-col flex-1 min-h-0">{content}</div></div>)}diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/VirtualizedTasksList.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/VirtualizedTasksList.tsxnew file mode 100644index 000000000000..77938996cbbe--- /dev/null+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/VirtualizedTasksList.tsx@@ -0,0 +1,101 @@+import { CSSProperties, useEffect, useRef } from 'react'+import { List, useDynamicRowHeight } from 'react-window'++import { AutoSizer } from 'lib/components/AutoSizer'+import { Spinner } from 'lib/lemon-ui/Spinner'++import { Task } from '../../../types/taskTypes'+import { TaskListItem } from './TaskListItem'++// Menu-item row height; the dynamic measurer corrects rows whose title wraps to two lines.+const DEFAULT_TASK_ROW_HEIGHT = 40+// Start fetching the next page this many rows before the end so it lands before the user hits the bottom.+const LOAD_MORE_THRESHOLD = 5++interface TaskRowProps {+ tasks: Task[]+ selectedTaskId: string | null+ dynamicRowHeight: ReturnType<typeof useDynamicRowHeight>+}++function TaskRow({+ index,+ style,+ tasks,+ selectedTaskId,+ dynamicRowHeight,+}: {+ ariaAttributes: Record<string, unknown>+ index: number+ style: CSSProperties+} & TaskRowProps): JSX.Element {+ const rowRef = useRef<HTMLDivElement>(null)++ useEffect(() => {+ if (rowRef.current) {+ return dynamicRowHeight.observeRowElements([rowRef.current])+ }+ }, [dynamicRowHeight])++ // The trailing row past the end of `tasks` is the infinite-scroll loader.+ const task = tasks[index]++ return (+ <div ref={rowRef} style={style} data-index={index} className="px-4 lg:px-0">+ {task ? (+ <TaskListItem task={task} isActive={task.id === selectedTaskId} />+ ) : (+ <div className="flex items-center justify-center py-3">+ <Spinner />+ </div>+ )}+ </div>+ )+}++interface VirtualizedTasksListProps {+ tasks: Task[]+ /** Currently selected task id, used to highlight its row. */+ selectedTaskId: string | null+ /** Whether another page can be fetched (the response still has a `next` cursor). */+ hasMore: boolean+ /** Whether a page fetch is already in flight, to avoid duplicate loads. */+ loadingMore: boolean+ onLoadMore: () => void+}++export function VirtualizedTasksList({+ tasks,+ selectedTaskId,+ hasMore,+ loadingMore,+ onLoadMore,+}: VirtualizedTasksListProps): JSX.Element {+ const dynamicRowHeight = useDynamicRowHeight({ defaultRowHeight: DEFAULT_TASK_ROW_HEIGHT })++ // One extra row hosts the loader spinner while more pages remain.+ const rowCount = tasks.length + (hasMore ? 1 : 0)++ return (+ <AutoSizer+ renderProp={({ height, width }) =>+ height && width ? (+ <List<TaskRowProps>+ style={{ height, width }}+ className="py-4 overflow-x-hidden"+ overscanCount={10}+ rowCount={rowCount}+ rowHeight={dynamicRowHeight}+ rowComponent={TaskRow}+ rowProps={{ tasks, selectedTaskId, dynamicRowHeight }}+ onRowsRendered={({ stopIndex }) => {+ if (hasMore && !loadingMore && stopIndex >= tasks.length - LOAD_MORE_THRESHOLD) {+ onLoadMore()+ }+ }}+ />+ ) : null+ }+ />+ )+}