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(replay-vision): prevent daily digest card flash on turn-on (#71272)

Kim Svatos Dugan52f966ec4282
diff --git a/products/replay_vision/frontend/replay_scanners/scannerDigestLogic.test.ts b/products/replay_vision/frontend/replay_scanners/scannerDigestLogic.test.ts
index 15e7ee8bcfe1..d21dca6ca309 100644
--- a/products/replay_vision/frontend/replay_scanners/scannerDigestLogic.test.ts
+++ b/products/replay_vision/frontend/replay_scanners/scannerDigestLogic.test.ts
@@ -78,7 +78,7 @@ describe('scannerDigestLogic', () => {
expect(logic.values.latestRunLoading).toEqual(false)
})
- it('one-click create sends the digest marker and defaults, then reloads the list', async () => {
+ it('one-click create sends the digest marker and defaults, then settles without a card flash', async () => {
useMocks(mocksFor([]))
mountLogic()
await expectLogic(logic).toFinishAllListeners()
@@ -91,10 +91,12 @@ describe('scannerDigestLogic', () => {
},
},
})
+ // Optimistic insert + local run resolution instead of a refetch: refetching would blank the
+ // card (digest absent while the list reloads, then latestRunLoading true) and flash it.
await expectLogic(logic, () => {
logic.actions.createDigest()
})
- .toDispatchActions(['createDigestSuccess', 'loadActions'])
+ .toDispatchActions(['createDigestSuccess', 'addAction', 'loadLatestRunSuccess'])
.toFinishAllListeners()
expect(body).toMatchObject({
name: 'Daily digest: my-scanner',
@@ -103,5 +105,8 @@ describe('scannerDigestLogic', () => {
trigger_config: { rrule: 'FREQ=DAILY;BYHOUR=8;BYMINUTE=0' },
delivery_config: [],
})
+ // The card renders the created digest immediately (no null-rendering gap).
+ expect(logic.values.digest?.id).toEqual('d-new')
+ expect(logic.values.latestRunLoading).toEqual(false)
})
})
diff --git a/products/replay_vision/frontend/replay_scanners/scannerDigestLogic.ts b/products/replay_vision/frontend/replay_scanners/scannerDigestLogic.ts
index 7405685c7a98..5cf3c633d8c6 100644
--- a/products/replay_vision/frontend/replay_scanners/scannerDigestLogic.ts
+++ b/products/replay_vision/frontend/replay_scanners/scannerDigestLogic.ts
@@ -29,7 +29,7 @@ export const scannerDigestLogic = kea<scannerDigestLogicType>([
values: [visionActionsLogic({ scannerId: props.scannerId }), ['visionActions', 'visionActionsLoading']],
actions: [
visionActionsLogic({ scannerId: props.scannerId }),
- ['loadActions', 'loadActionsSuccess', 'toggleActionEnabled'],
+ ['loadActions', 'loadActionsSuccess', 'toggleActionEnabled', 'addAction'],
],
})),
@@ -125,7 +125,7 @@ export const scannerDigestLogic = kea<scannerDigestLogicType>([
return
}
try {
- await visionActionsCreate(String(teamId), {
+ const created = await visionActionsCreate(String(teamId), {
// Mirrors the backend provisioning defaults (digest.py) for scanners created before
// digests existed, or after the digest was deleted.
name: `Daily digest: ${props.scannerName}`.slice(0, 255),
@@ -139,7 +139,12 @@ export const scannerDigestLogic = kea<scannerDigestLogicType>([
})
actions.createDigestSuccess()
lemonToast.success('Daily digest turned on')
- actions.loadActions()
+ // Insert the created digest optimistically instead of refetching the list — a refetch
+ // would blank the card (visionActionsLoading true, digest still absent) and flash it.
+ actions.addAction(created)
+ // A brand-new digest has no runs yet, so resolve the run state locally rather than
+ // fetching; this keeps the card from flashing through its latestRunLoading gap.
+ actions.loadLatestRunSuccess(null)
} catch (error: any) {
actions.createDigestFailure()
lemonToast.error(`Couldn't turn on the daily digest${error?.detail ? `: ${error.detail}` : ''}`)
diff --git a/products/replay_vision/frontend/replay_scanners/visionActionsLogic.ts b/products/replay_vision/frontend/replay_scanners/visionActionsLogic.ts
index dccf1afe8c8d..fddc5a260195 100644
--- a/products/replay_vision/frontend/replay_scanners/visionActionsLogic.ts
+++ b/products/replay_vision/frontend/replay_scanners/visionActionsLogic.ts
@@ -133,6 +133,7 @@ export const visionActionsLogic = kea<visionActionsLogicType>([
loadActions: true,
loadActionsSuccess: (visionActions: VisionActionApi[]) => ({ visionActions }),
loadActionsFailure: true,
+ addAction: (action: VisionActionApi) => ({ action }),
toggleActionEnabled: (id: string) => ({ id }),
revertActionEnabled: (id: string) => ({ id }),
toggleActionEnabledDone: (id: string) => ({ id }),
@@ -145,6 +146,7 @@ export const visionActionsLogic = kea<visionActionsLogicType>([
[] as VisionActionApi[],
{
loadActionsSuccess: (_, { visionActions }) => visionActions,
+ addAction: (state, { action }) => [...state, action],
deleteActionSuccess: (state, { id }) => state.filter((a) => a.id !== id),
// Optimistic flip on toggle; revert mirrors it back on failure.
toggleActionEnabled: (state, { id }) =>