Skip to content

: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.

fix(inbox): keep scrolling past the first page of reports (#85389)

Andrew Maguireedc8cec5e831
diff --git a/products/signals/frontend/inbox/components/InboxReportList.test.tsx b/products/signals/frontend/inbox/components/InboxReportList.test.tsx
new file mode 100644
index 000000000000..d5b1b29244cb
--- /dev/null
+++ b/products/signals/frontend/inbox/components/InboxReportList.test.tsx
@@ -0,0 +1,111 @@
+import '@testing-library/jest-dom'
+
+import { act, cleanup, render, screen, waitFor } from '@testing-library/react'
+
+import { useMocks } from '~/mocks/jest'
+import { initKeaTests } from '~/test/init'
+
+import { INBOX_FLAT_TAB_LIST_PARAMS } from '../logics/reportListLogic'
+import { SignalReport, SignalReportStatus } from '../types'
+import { InboxReportList, InboxReportCardProps } from './InboxReportList'
+
+// The list chrome is unrelated to paging and pulls in its own scout/filter endpoints.
+jest.mock('./shell/InboxSearchFilterBar', () => ({ InboxSearchFilterBar: () => null }))
+jest.mock('./shell/InboxBulkSelectionBar', () => ({ InboxBulkSelectionBar: () => null }))
+
+/** Fires whatever the component handed to `IntersectionObserver.observe`, as if it scrolled into view. */
+let intersectObservedElement: (() => void) | null = null
+
+function StubCard({ report }: InboxReportCardProps): JSX.Element {
+ return <div>{report.title}</div>
+}
+
+function makeReport(id: string): SignalReport {
+ return {
+ id,
+ title: `Report ${id}`,
+ summary: 'summary',
+ status: SignalReportStatus.READY,
+ total_weight: 0,
+ signal_count: 1,
+ relevant_user_count: null,
+ artefact_count: 0,
+ is_suggested_reviewer: false,
+ priority: 'P2',
+ source_products: ['error_tracking'],
+ created_at: '2026-06-11T10:00:00Z',
+ updated_at: '2026-06-11T10:00:00Z',
+ } satisfies SignalReport
+}
+
+describe('InboxReportList', () => {
+ let requestedOffsets: (string | null)[]
+
+ beforeAll(() => {
+ // jsdom has no IntersectionObserver; the infinite-scroll sentinel needs one.
+ global.IntersectionObserver = class {
+ constructor(private callback: IntersectionObserverCallback) {}
+ observe(): void {
+ intersectObservedElement = () =>
+ this.callback([{ isIntersecting: true } as IntersectionObserverEntry], this as any)
+ }
+ unobserve(): void {}
+ disconnect(): void {}
+ } as unknown as typeof IntersectionObserver
+ })
+
+ beforeEach(() => {
+ intersectObservedElement = null
+ requestedOffsets = []
+ useMocks({
+ get: {
+ // Reviewer scope loads alongside the list; an empty map keeps it out of the way.
+ '/api/projects/:team_id/signals/reports/available_reviewers': {},
+ '/api/projects/:team_id/signals/reports/': ({ request }) => {
+ const { searchParams } = new URL(request.url)
+ const offset = searchParams.get('offset')
+ const limit = searchParams.get('limit')
+ // The tab badge fires a separate count-only request; don't count it as a page.
+ if (limit !== '1') {
+ requestedOffsets.push(offset)
+ }
+ const page = offset === '0' || offset === null ? '1' : '2'
+ return [
+ 200,
+ {
+ count: 277,
+ // A non-null `next` is what tells the list there are more pages.
+ next: 'http://localhost/api/projects/997/signals/reports/?offset=50',
+ previous: null,
+ results: [makeReport(`page-${page}`)],
+ },
+ ]
+ },
+ },
+ })
+ initKeaTests()
+ })
+
+ afterEach(cleanup)
+
+ it('keeps paging once the sentinel scrolls into view', async () => {
+ render(
+ <InboxReportList
+ tabKey="reports"
+ listParams={INBOX_FLAT_TAB_LIST_PARAMS.reports}
+ Card={StubCard}
+ emptyState={{ content: <div>empty</div> }}
+ />
+ )
+
+ await screen.findByText('Report page-1')
+ // The sentinel only enters the DOM after the first page lands, so the observer has to
+ // attach then — not on mount, when there is nothing to observe.
+ await waitFor(() => expect(intersectObservedElement).not.toBeNull())
+
+ act(() => intersectObservedElement!())
+
+ await screen.findByText('Report page-2')
+ expect(requestedOffsets).toEqual(['0', '1'])
+ })
+})
diff --git a/products/signals/frontend/inbox/components/InboxReportList.tsx b/products/signals/frontend/inbox/components/InboxReportList.tsx
index 00d00656f3da..8d0344393f7e 100644
--- a/products/signals/frontend/inbox/components/InboxReportList.tsx
+++ b/products/signals/frontend/inbox/components/InboxReportList.tsx
@@ -1,5 +1,5 @@
import { BindLogic, useActions, useValues } from 'kea'
-import { ComponentType, JSX, useEffect, useRef } from 'react'
+import { ComponentType, JSX, useCallback, useEffect, useRef } from 'react'
import { captureInboxReportsImpressed, captureInboxViewed } from '../inboxAnalytics'
import { inboxSceneLogic } from '../inboxSceneLogic'
@@ -53,7 +53,6 @@ function InboxReportListInner({ tabKey, Card, emptyState }: InboxReportListProps
// `Inbox viewed` and then suppresses the real one when the user navigates back to the list.
const { selectedReportId, selectedScoutSkillName, isScratchpadOpen, isFindingsOpen } = useValues(inboxSceneLogic)
const listVisible = !selectedReportId && !selectedScoutSkillName && !isScratchpadOpen && !isFindingsOpen
- const sentinelRef = useRef<HTMLDivElement>(null)
// The Pull requests / Reports badge counts go on every `Inbox viewed`, whatever tab is open: the
// active tab's `total_count` alone says nothing about a user who lands on Pull requests and has
@@ -141,8 +140,8 @@ function InboxReportListInner({ tabKey, Card, emptyState }: InboxReportListProps
})
}, [listVisible, isLoaded, totalCount, reports, tabKey, loadedQueryKey, loadedContext])
- // Read fresh state at intersection time via refs so the observer is created once and not
- // rebuilt twice per page fetch (`hasMore`/`reportsResponseLoading` both flip during a load).
+ // Read fresh state at intersection time via refs so the observer isn't rebuilt twice per page
+ // fetch (`hasMore`/`reportsResponseLoading` both flip during a load).
const hasMoreRef = useRef(hasMore)
hasMoreRef.current = hasMore
const loadingRef = useRef(reportsResponseLoading)
@@ -152,23 +151,32 @@ function InboxReportListInner({ tabKey, Card, emptyState }: InboxReportListProps
ensureLoaded()
}, [ensureLoaded])
- useEffect(() => {
- const el = sentinelRef.current
- if (!el) {
- return
- }
- const observer = new IntersectionObserver(
- (entries) => {
- if (entries[0]?.isIntersecting && hasMoreRef.current && !loadingRef.current) {
- loadMore()
- }
- },
- // Generous prefetch margin so the next page lands well before the user reaches the bottom.
- { rootMargin: '1500px' }
- )
- observer.observe(el)
- return () => observer.disconnect()
- }, [loadMore])
+ // A callback ref, not an effect over `sentinelRef`: the sentinel only enters the DOM once the
+ // first page has landed and `hasMore` is true, which is after a mount-only effect has already
+ // run and found nothing to observe. Attaching as the node mounts is what keeps paging alive.
+ const observerRef = useRef<IntersectionObserver | null>(null)
+ const sentinelRef = useCallback(
+ (el: HTMLDivElement | null) => {
+ observerRef.current?.disconnect()
+ observerRef.current = null
+ if (!el) {
+ return
+ }
+ const observer = new IntersectionObserver(
+ (entries) => {
+ if (entries[0]?.isIntersecting && hasMoreRef.current && !loadingRef.current) {
+ loadMore()
+ }
+ },
+ // Generous prefetch margin so the next page lands well before the user reaches the bottom.
+ { rootMargin: '1500px' }
+ )
+ observer.observe(el)
+ observerRef.current = observer
+ },
+ [loadMore]
+ )
+ useEffect(() => () => observerRef.current?.disconnect(), [])
// Skeleton while a tab we know is non-empty loads its first page.
const showSkeleton = !isLoaded && (reportsResponseLoading || (count ?? 0) > 0)