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(signals): stop the inbox repainting every row on each update (#106081)

posthog[bot]5900e915feea
diff --git a/products/signals/frontend/inbox/components/InboxReportList.tsx b/products/signals/frontend/inbox/components/InboxReportList.tsx
index 2c8193f5e711..084cab47058d 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, useCallback, useEffect, useRef } from 'react'
+import { ComponentType, JSX, memo, useCallback, useEffect, useRef } from 'react'
import { LemonButton } from '@posthog/lemon-ui'
@@ -31,6 +31,34 @@ interface InboxReportListProps {
| { icon: JSX.Element; title: string; description: string; extra?: JSX.Element }
}
+/**
+ * One row, memoized. The list re-renders on every badge count, page and poll that lands, and
+ * repainting every row each time is what made the inbox stop answering clicks. The row builds its
+ * own dismiss and restore closures from the list's stable actions, so its props stay comparable.
+ */
+const LegacyReportRow = memo(function LegacyReportRow({
+ report,
+ sectionKey,
+ Card,
+ dismissReport,
+ restoreReport,
+}: {
+ report: SignalReport
+ sectionKey: InboxReportSectionKey
+ Card: ComponentType<InboxReportCardProps>
+ dismissReport: (reportId: string, dismissal: DismissalFeedback) => void
+ restoreReport: (reportId: string, surface: 'list_row') => void
+}): JSX.Element {
+ return (
+ <Card
+ report={report}
+ sectionKey={sectionKey}
+ onDismiss={(dismissal) => dismissReport(report.id, dismissal)}
+ onRestore={() => restoreReport(report.id, 'list_row')}
+ />
+ )
+})
+
/**
* Shared body for the flat report-list tabs shown with the redesign flag off (Pull requests /
* Reports / Not actionable / Archive). Each is the same primitive – only the server filter and
@@ -233,12 +261,13 @@ function InboxReportListInner({ tabKey, Card, emptyState }: InboxReportListProps
{/* Each report is its own freestanding card, separated by a small gap. */}
<div className="flex flex-col gap-1.5">
{reports.map((report) => (
- <Card
+ <LegacyReportRow
key={report.id}
report={report}
sectionKey={INBOX_LEGACY_TAB_SECTION[tabKey]}
- onDismiss={(dismissal) => dismissReport(report.id, dismissal)}
- onRestore={() => restoreReport(report.id, 'list_row')}
+ Card={Card}
+ dismissReport={dismissReport}
+ restoreReport={restoreReport}
/>
))}
{/* Skeleton cards continue the list while the next page loads – sleeker than a spinner. */}
diff --git a/products/signals/frontend/inbox/components/cards/ReportCard.test.tsx b/products/signals/frontend/inbox/components/cards/ReportCard.test.tsx
index d14bf2b45161..f83854b1aab8 100644
--- a/products/signals/frontend/inbox/components/cards/ReportCard.test.tsx
+++ b/products/signals/frontend/inbox/components/cards/ReportCard.test.tsx
@@ -4,6 +4,7 @@ import { act, cleanup, fireEvent, render, screen, within } from '@testing-librar
import userEvent from '@testing-library/user-event'
import { router } from 'kea-router'
import posthog from 'posthog-js'
+import { Profiler } from 'react'
import api from 'lib/api'
import { FEATURE_FLAGS } from 'lib/constants'
@@ -11,10 +12,11 @@ import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { initKeaTests } from '~/test/init'
-import type { ReportMetricApi } from 'products/signals/frontend/generated/api.schemas'
+import { PullRequestCiStatusEnumApi, type ReportMetricApi } from 'products/signals/frontend/generated/api.schemas'
import { INBOX_EVENTS } from '../../inboxAnalytics'
import { inboxBulkActionsLogic } from '../../logics/inboxBulkActionsLogic'
+import { prCiStatusLogic } from '../../logics/prCiStatusLogic'
import { SignalReport, SignalReportStatus } from '../../types'
import { SELECTION_HOLD_MS } from '../../utils/reportSelection'
import { ReportCard } from './ReportCard'
@@ -399,4 +401,48 @@ describe('ReportCard', () => {
)
expect(container.querySelector('[data-attr="report-card-impact-metric"]')).toBeNull()
})
+
+ /**
+ * Render two cards, each behind its own profiler, and hand back the per-card render tally.
+ * A card that skips a store change never commits, so its count stands still.
+ */
+ function renderCountedPair(): Record<string, number> {
+ cleanup()
+ const renders: Record<string, number> = { 'r-1': 0, 'r-2': 0 }
+ render(
+ <>
+ {['r-1', 'r-2'].map((id) => (
+ <Profiler key={id} id={id} onRender={() => (renders[id] += 1)}>
+ <ReportCard report={makeReport(id)} selectable />
+ </Profiler>
+ ))}
+ </>
+ )
+ return renders
+ }
+
+ it('repaints only the row whose selection changed', () => {
+ const renders = renderCountedPair()
+ // Selection mode is already on, so the only thing this toggle changes is one row's own flag.
+ act(() => logic.actions.setSelectedReportIds(['r-3']))
+ const before = { ...renders }
+
+ act(() => logic.actions.toggleReportSelection('r-1'))
+
+ expect(renders['r-1']).toBeGreaterThan(before['r-1'])
+ expect(renders['r-2']).toBe(before['r-2'])
+ })
+
+ it('repaints only the row whose CI state changed', () => {
+ const ciLogic = prCiStatusLogic()
+ ciLogic.mount()
+ const renders = renderCountedPair()
+ const before = { ...renders }
+
+ act(() => ciLogic.actions.loadCiStatusesSuccess({ 'r-1': PullRequestCiStatusEnumApi.Failing }))
+
+ expect(renders['r-1']).toBeGreaterThan(before['r-1'])
+ expect(renders['r-2']).toBe(before['r-2'])
+ ciLogic.unmount()
+ })
})
diff --git a/products/signals/frontend/inbox/components/cards/ReportCard.tsx b/products/signals/frontend/inbox/components/cards/ReportCard.tsx
index acda2ee5bc1c..f83496d4fc39 100644
--- a/products/signals/frontend/inbox/components/cards/ReportCard.tsx
+++ b/products/signals/frontend/inbox/components/cards/ReportCard.tsx
@@ -1,6 +1,6 @@
import clsx from 'clsx'
-import { useValues } from 'kea'
import { router } from 'kea-router'
+import { memo } from 'react'
import { IconHide, IconUndo } from '@posthog/icons'
import { LemonButton, LemonTag, Link, Tooltip } from '@posthog/lemon-ui'
@@ -12,7 +12,7 @@ import { ScoutLink } from 'lib/signals/ScoutLink'
import { scoutDisplayName } from 'lib/signals/signalCardSourceLine'
import { PrBadge } from 'lib/signals/SignalReportPrBadge'
-import { prCiStatusLogic } from '../../logics/prCiStatusLogic'
+import { useReportCiStatus } from '../../logics/prCiStatusLogic'
import {
INBOX_SECTION_LEGACY_TAB,
InboxReportSectionKey,
@@ -113,7 +113,7 @@ export function InboxCardSourceMeta({
* and actionability chips: the state a row is in (Needs decision, Not actionable, ...) already says
* what they said. With the flag off every row keeps its chips, its Dismiss button, and "Review".
*/
-export function ReportCard({
+function ReportCardRaw({
report,
sectionKey = 'needs-decision',
attached = false,
@@ -179,8 +179,7 @@ export function ReportCard({
})
// Painted from the shared map the report lists fill; absent until (or unless) GitHub answers.
- const { ciStatusByReportId } = useValues(prCiStatusLogic)
- const ciStatus = preview ? null : ciStatusByReportId[report.id]
+ const ciStatus = useReportCiStatus(preview ? null : report.id)
const prState = derivePrState(
report.status,
primaryReportPullRequest(report).merged === true,
@@ -421,3 +420,10 @@ export function ReportCard({
</div>
)
}
+
+/**
+ * Memoized because the inbox list re-renders many times over a load — five state requests, their
+ * counts, the CI poll, and every filter click — and a few hundred unmemoized rows of this depth is
+ * what made the page stop answering the pointer. A row now repaints only when its own report does.
+ */
+export const ReportCard = memo(ReportCardRaw)
diff --git a/products/signals/frontend/inbox/components/cards/useReportCardSelection.ts b/products/signals/frontend/inbox/components/cards/useReportCardSelection.ts
index e8d27ae0764a..f9e00d4a3003 100644
--- a/products/signals/frontend/inbox/components/cards/useReportCardSelection.ts
+++ b/products/signals/frontend/inbox/components/cards/useReportCardSelection.ts
@@ -1,4 +1,4 @@
-import { useActions, useValues } from 'kea'
+import { useActions, useSelector, useValues } from 'kea'
import { MouseEvent, PointerEvent, useCallback, useEffect, useRef, useState } from 'react'
import { captureInboxSelectionModeEntered, InboxSelectionEntryMethod } from '../../inboxAnalytics'
@@ -40,8 +40,14 @@ export interface ReportCardSelection {
* pointer events into its actions, and it does nothing at all on a row the list marks unselectable.
*/
export function useReportCardSelection(reportId: string, enabled: boolean): ReportCardSelection {
- const { selectedReportIds, hasSelection, isDismissing, isResolving } = useValues(inboxBulkActionsLogic)
+ const { hasSelection, isDismissing, isResolving } = useValues(inboxBulkActionsLogic)
const { toggleReportSelection, selectRange } = useActions(inboxBulkActionsLogic)
+ // Only this row's own flag, not the id list: reading the list subscribed every card to every
+ // other card's selection, so picking one row repainted the whole inbox. The booleans above
+ // stay subscribed because they really do change what every row does on a click.
+ const isReportSelected: boolean = useSelector((state) =>
+ inboxBulkActionsLogic.selectors.selectedReportIds(state).includes(reportId)
+ )
const selectionDisabled = isDismissing || isResolving
const holdTimerRef = useRef<number | null>(null)
@@ -162,7 +168,7 @@ export function useReportCardSelection(reportId: string, enabled: boolean): Repo
)
return {
- isSelected: enabled && selectedReportIds.includes(reportId),
+ isSelected: enabled && isReportSelected,
selectionMode: enabled && hasSelection,
isHolding,
selectionDisabled,
diff --git a/products/signals/frontend/inbox/components/tabs/ReportsTab.tsx b/products/signals/frontend/inbox/components/tabs/ReportsTab.tsx
index dd96971f784d..300837ed0932 100644
--- a/products/signals/frontend/inbox/components/tabs/ReportsTab.tsx
+++ b/products/signals/frontend/inbox/components/tabs/ReportsTab.tsx
@@ -1,5 +1,5 @@
import { useMountedLogic, useValues } from 'kea'
-import { JSX, useCallback, useEffect, useRef } from 'react'
+import { JSX, memo, useCallback, useEffect, useRef } from 'react'
import { IconNotebook } from '@posthog/icons'
import { LemonButton } from '@posthog/lemon-ui'
@@ -153,6 +153,32 @@ function useInboxViewedEvent(sections: Record<CountedSectionKey, SectionListStat
])
}
+/**
+ * One row of the flat list, memoized. The list above it re-renders on every count, page and poll
+ * that lands, and repainting a few hundred rows each time is what made the inbox stop answering
+ * clicks. The restore closure is built here so the row's props stay comparable.
+ */
+const ReportRow = memo(function ReportRow({
+ report,
+ sectionKey,
+}: {
+ report: SignalReport
+ sectionKey: InboxReportSectionKey
+}): JSX.Element {
+ return (
+ <ReportContextMenu report={report} sectionKey={sectionKey}>
+ <ReportCard
+ report={report}
+ sectionKey={sectionKey}
+ selectable
+ onRestore={() =>
+ reportListLogic(sectionListLogicProps(sectionKey)).actions.restoreReport(report.id, 'list_row')
+ }
+ />
+ </ReportContextMenu>
+ )
+})
+
/** Nothing has reached the inbox yet — the whole list is empty, not just one state. */
function ReportsEmptyState(): JSX.Element {
const { featureFlags } = useValues(featureFlagLogic)
@@ -357,19 +383,7 @@ export function ReportsTab(): JSX.Element {
) : (
<div className="@container flex flex-col gap-1.5">
{rows.map(({ report, sectionKey }) => (
- <ReportContextMenu key={report.id} report={report} sectionKey={sectionKey}>
- <ReportCard
- report={report}
- sectionKey={sectionKey}
- selectable
- onRestore={() =>
- reportListLogic(sectionListLogicProps(sectionKey)).actions.restoreReport(
- report.id,
- 'list_row'
- )
- }
- />
- </ReportContextMenu>
+ <ReportRow key={report.id} report={report} sectionKey={sectionKey} />
))}
{/* Skeleton cards continue the list while the next pages load – sleeker than a spinner. */}
{pageLoading && <CardSkeleton count={2} variant="cards" dashed />}
diff --git a/products/signals/frontend/inbox/logics/prCiStatusLogic.ts b/products/signals/frontend/inbox/logics/prCiStatusLogic.ts
index 4187d12fa12b..8d2a191d57ce 100644
--- a/products/signals/frontend/inbox/logics/prCiStatusLogic.ts
+++ b/products/signals/frontend/inbox/logics/prCiStatusLogic.ts
@@ -1,4 +1,15 @@
-import { MakeLogicType, actions, afterMount, kea, listeners, path, reducers, selectors } from 'kea'
+import {
+ MakeLogicType,
+ actions,
+ afterMount,
+ kea,
+ listeners,
+ path,
+ reducers,
+ selectors,
+ useMountedLogic,
+ useSelector,
+} from 'kea'
import { loaders } from 'kea-loaders'
import { teamLogic } from 'scenes/teamLogic'
@@ -223,3 +234,15 @@ export const prCiStatusLogic = kea<prCiStatusLogicType>([
}, 'prCiStatusPoll')
}),
])
+
+/**
+ * One row's CI state. A row must read only its own entry: subscribing to the whole map made every
+ * card in the list repaint each time the minute poll answered, which is a few hundred cards of
+ * React work for a glyph on one of them.
+ */
+export function useReportCiStatus(reportId: string | null): PullRequestCiStatusEnumApi | undefined {
+ useMountedLogic(prCiStatusLogic)
+ return useSelector((state) =>
+ reportId ? prCiStatusLogic.selectors.ciStatusByReportId(state)[reportId] : undefined
+ )
+}