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): preserve inbox claims during page loads (#130402)

Dylan Martin8ba66b1f5a40
diff --git a/products/signals/frontend/inbox/logics/reportListLogic.test.ts b/products/signals/frontend/inbox/logics/reportListLogic.test.ts
index 63c9f44244a8..6bb0a967e9d7 100644
--- a/products/signals/frontend/inbox/logics/reportListLogic.test.ts
+++ b/products/signals/frontend/inbox/logics/reportListLogic.test.ts
@@ -340,27 +340,66 @@ describe('reportListLogic', () => {
bulkLogic.unmount()
})
- it('keeps a claim made while the first page reloads, which the reload read before the claim saved', async () => {
- let releasePage: () => void = () => {}
- const heldPage = new Promise<void>((resolve) => {
- releasePage = resolve
- })
- useMocks({
- get: {
- [REPORTS_URL]: async () => {
- await heldPage
- return [200, { count: FIRST_PAGE.length, next: null, previous: null, results: FIRST_PAGE }]
- },
+ it.each(
+ [
+ { name: 'claim', scope: INBOX_SCOPE_ENTIRE_PROJECT, before: null, after: myClaim },
+ { name: 'release', scope: INBOX_SCOPE_ENTIRE_PROJECT, before: myClaim, after: null },
+ {
+ name: 'release from Claimed by you',
+ scope: INBOX_SCOPE_CLAIMED_BY_YOU,
+ before: myClaim,
+ after: null,
},
- })
+ ].flatMap((testCase) => ['first', 'next'].map((page) => ({ ...testCase, page })))
+ )('keeps a $name while the $page page loads', async ({ scope, before, after, page }) => {
+ const bulkLogic = inboxBulkActionsLogic()
+ bulkLogic.mount()
+ try {
+ logic.actions.setScope(scope)
+ await expectLogic(logic).toFinishAllListeners()
+ logic.actions.setReportAssignee(FIRST_PAGE[0].id, before)
+ const staleRows = page === 'first' ? logic.values.reportsResponse!.results : SECOND_PAGE
+ let releasePage: () => void = () => {}
+ const heldPage = new Promise<void>((resolve) => {
+ releasePage = resolve
+ })
+ useMocks({
+ get: {
+ [REPORTS_URL]: async () => {
+ await heldPage
+ return [
+ 200,
+ {
+ count: FIRST_PAGE.length + SECOND_PAGE.length,
+ next: null,
+ previous: null,
+ results: staleRows,
+ },
+ ]
+ },
+ },
+ })
- logic.actions.loadReports()
- logic.actions.setReportAssignee(FIRST_PAGE[0].id, myClaim)
- releasePage()
- await expectLogic(logic).toFinishAllListeners()
+ if (page === 'first') {
+ logic.actions.loadReports()
+ } else {
+ logic.actions.loadMore()
+ }
+ bulkLogic.actions.reportClaimChanged(FIRST_PAGE[0].id, after)
+ const expectedRow = scope === INBOX_SCOPE_CLAIMED_BY_YOU ? undefined : { assignee: after }
+ if (expectedRow) {
+ expect(logic.values.reports.find((r) => r.id === FIRST_PAGE[0].id)).toMatchObject(expectedRow)
+ } else {
+ expect(logic.values.reports.find((r) => r.id === FIRST_PAGE[0].id)).toBeUndefined()
+ }
+ const rowsAfterWrite = logic.values.reports
+ releasePage()
+ await expectLogic(logic).toFinishAllListeners()
- expect(logic.values.reports.find((r) => r.id === FIRST_PAGE[0].id)?.assignee).toEqual(myClaim)
- expect(logic.values.reports.find((r) => r.id === FIRST_PAGE[1].id)?.assignee).toBeUndefined()
+ expect(logic.values.reports).toEqual([...rowsAfterWrite, ...(page === 'next' ? SECOND_PAGE : [])])
+ } finally {
+ bulkLogic.unmount()
+ }
})
it('keeps a row removed while the next page is in flight out of the appended list', async () => {
@@ -378,7 +417,7 @@ describe('reportListLogic', () => {
count: FIRST_PAGE.length + SECOND_PAGE.length,
next: null,
previous: null,
- results: SECOND_PAGE,
+ results: [FIRST_PAGE[3], ...SECOND_PAGE],
},
]
},
diff --git a/products/signals/frontend/inbox/logics/reportListLogic.ts b/products/signals/frontend/inbox/logics/reportListLogic.ts
index 122ed5e9e04b..a05ab7537c64 100644
--- a/products/signals/frontend/inbox/logics/reportListLogic.ts
+++ b/products/signals/frontend/inbox/logics/reportListLogic.ts
@@ -695,10 +695,6 @@ export const reportListLogic = kea<reportListLogicType>([
const requestContext = requestContextFromValues(values)
const firstPageRequestId = cache.firstPageRequestId
const current = values.reportsResponse?.results ?? []
- // `removeReport` records ids here while the request is in flight. `current` predates
- // those removals, so filter them out or a removed report comes back when the page lands.
- const removedWhilePending = new Set<string>()
- cache.removedWhilePageLoads = removedWhilePending
// nosemgrep: prefer-codegen-api-namespaced-signals -- the Inbox renders the handwritten SignalReport. The generated report type is wider (string status and priority, read-only arrays), so the list calls move to generated types together with the Inbox.
const response = await api.signalReports.list({
...listRequestParams(params),
@@ -710,9 +706,10 @@ export const reportListLogic = kea<reportListLogicType>([
if (cache.firstPageRequestId !== firstPageRequestId && values.reportsResponse) {
return values.reportsResponse
}
+ const latest = values.reportsResponse?.results ?? []
return {
...response,
- results: [...current.filter((r) => !removedWhilePending.has(r.id)), ...response.results],
+ results: [...latest, ...keepRowFieldsWrittenDuringFetch(response.results, current, latest)],
requestParams: params,
requestContext,
}
@@ -1023,9 +1020,6 @@ export const reportListLogic = kea<reportListLogicType>([
requested.forEach((id) => inFlight.delete(id))
}
},
- removeReport: ({ reportId }) => {
- cache.removedWhilePageLoads?.add(reportId)
- },
// One page of ids per request, sent one after the other so a page open never fans out into
// parallel query bursts. A newer page load supersedes an in-flight refresh at the breakpoint.
refreshReportMetrics: async ({ reportIds }, breakpoint) => {
diff --git a/products/signals/frontend/inbox/utils/reportFreshness.ts b/products/signals/frontend/inbox/utils/reportFreshness.ts
index e2bdfa2b036a..11469bcdbb3b 100644
--- a/products/signals/frontend/inbox/utils/reportFreshness.ts
+++ b/products/signals/frontend/inbox/utils/reportFreshness.ts
@@ -48,5 +48,7 @@ export function keepRowFieldsWrittenDuringFetch<T extends ReportCopy>(
}
const beforeById = new Map(before.map((row) => [row.id, row]))
const currentById = new Map(current.map((row) => [row.id, row]))
- return fetched.map((row) => keepFieldsWrittenDuringFetch(row, beforeById.get(row.id), currentById.get(row.id)))
+ return fetched
+ .filter((row) => !beforeById.has(row.id) || currentById.has(row.id))
+ .map((row) => keepFieldsWrittenDuringFetch(row, beforeById.get(row.id), currentById.get(row.id)))
}