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 reviewer edits working when the context menu closes mid-save (#124351)

Dylan Martin6494e4472d63
diff --git a/products/signals/frontend/inbox/logics/inboxReportDetailLogic.test.ts b/products/signals/frontend/inbox/logics/inboxReportDetailLogic.test.ts
index 6e85a4c3d777..28de2f54d4bd 100644
--- a/products/signals/frontend/inbox/logics/inboxReportDetailLogic.test.ts
+++ b/products/signals/frontend/inbox/logics/inboxReportDetailLogic.test.ts
@@ -301,7 +301,9 @@ describe('inboxReportDetailLogic', () => {
})
afterEach(() => {
- logic.unmount()
+ if (logic.isMounted()) {
+ logic.unmount()
+ }
})
it('finishes slow pagination across polls and retains project-scoped activity, task runs, and reviewers', async () => {
@@ -493,6 +495,41 @@ describe('inboxReportDetailLogic', () => {
bulk.unmount()
}
})
+
+ it('broadcasts saved reviewers when the logic unmounts while the save is in flight', async () => {
+ const savedReviewer = { ...reviewer, user_uuid: 'saved-reviewer-uuid' }
+ let releaseSave: () => void = () => {}
+ const heldSave = new Promise<void>((resolve) => {
+ releaseSave = resolve
+ })
+ let saveStarted = false
+ const bulk = inboxBulkActionsLogic()
+ bulk.mount()
+ const broadcast = jest.spyOn(bulk.actions, 'reportReviewersChanged')
+ const toastError = jest.spyOn(lemonToast, 'error')
+ useMocks({
+ put: {
+ '/api/projects/:team_id/signals/reports/:id/reviewers/': async () => {
+ saveStarted = true
+ await heldSave
+ return { ...artefact, content: [savedReviewer] }
+ },
+ },
+ })
+ try {
+ logic.actions.updateReviewers([{ github_login: reviewer.github_login! }], [savedReviewer], 'remove')
+ await waitFor(() => expect(saveStarted).toBe(true))
+ logic.unmount()
+ releaseSave()
+ await waitFor(() => expect(broadcast).toHaveBeenCalledWith(REPORT.id, [savedReviewer.user_uuid]))
+ expect(toastError).not.toHaveBeenCalled()
+ } finally {
+ releaseSave()
+ broadcast.mockRestore()
+ toastError.mockRestore()
+ bulk.unmount()
+ }
+ })
})
describe('implementationSlotClaim', () => {
diff --git a/products/signals/frontend/inbox/logics/inboxReportDetailLogic.ts b/products/signals/frontend/inbox/logics/inboxReportDetailLogic.ts
index b4862b535d52..01ee1e0436a3 100644
--- a/products/signals/frontend/inbox/logics/inboxReportDetailLogic.ts
+++ b/products/signals/frontend/inbox/logics/inboxReportDetailLogic.ts
@@ -1760,7 +1760,10 @@ export const inboxReportDetailLogic = kea<inboxReportDetailLogicType>([
return
}
cache.reviewerWriteInFlight = true
- let saved = false
+ // The context menu picker unmounts this logic when the menu closes, which can happen while
+ // the request is in flight. Kea throws on `values` read through an unmounted logic, so take
+ // the saved reviewers from the response and touch local state only while still mounted.
+ let savedReviewerUuids: string[] | null = null
try {
const artefact = await signalsReportsReviewersUpdate(
String(ApiConfig.getCurrentProjectId()),
@@ -1774,25 +1777,31 @@ export const inboxReportDetailLogic = kea<inboxReportDetailLogicType>([
action,
}
)
- saved = true
- actions.loadReportArtefactsSuccess([
- ...(values.reportArtefacts ?? []).filter((existing) => existing.id !== artefact.id),
- artefact as SignalReportArtefact,
- ])
- await asyncActions.loadReportArtefacts()
+ savedReviewerUuids = ((artefact.content ?? []) as unknown as EnrichedReviewer[])
+ .map((reviewer) => reviewer.user?.uuid ?? reviewer.user_uuid)
+ .filter((uuid): uuid is string => !!uuid)
+ if (inboxReportDetailLogic.isMounted(props)) {
+ actions.loadReportArtefactsSuccess([
+ ...(values.reportArtefacts ?? []).filter((existing) => existing.id !== artefact.id),
+ artefact as SignalReportArtefact,
+ ])
+ await asyncActions.loadReportArtefacts()
+ }
} catch (error: any) {
- lemonToast.error(error?.detail || error?.message || 'Failed to update reviewers')
+ // After a successful save, an error from an unmounted logic is not a failed edit.
+ if (!savedReviewerUuids || inboxReportDetailLogic.isMounted(props)) {
+ lemonToast.error(error?.detail || error?.message || 'Failed to update reviewers')
+ }
} finally {
cache.reviewerWriteInFlight = false
- actions.setOptimisticReviewers(null)
+ if (inboxReportDetailLogic.isMounted(props)) {
+ actions.setOptimisticReviewers(null)
+ }
}
// Broadcast last: the list can drop the row that hosts this logic (the context menu picker),
// which unmounts it, and kea throws on an action dispatched through an unmounted logic.
- if (saved) {
- const reviewerUuids = (values.displayReviewers ?? [])
- .map((reviewer) => reviewer.user?.uuid ?? reviewer.user_uuid)
- .filter((uuid): uuid is string => !!uuid)
- inboxBulkActionsLogic.findMounted()?.actions.reportReviewersChanged(props.reportId, reviewerUuids)
+ if (savedReviewerUuids) {
+ inboxBulkActionsLogic.findMounted()?.actions.reportReviewersChanged(props.reportId, savedReviewerUuids)
}
},
// Post an inline review comment as the user. The comment is inserted optimistically (marked