: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(desktop): refresh comment activity notifications (#81962)
Shy Alter2643314cb385
diff --git a/products/desktop/packages/ui/src/features/canvas/hooks/useTaskActivity.test.tsx b/products/desktop/packages/ui/src/features/canvas/hooks/useTaskActivity.test.tsxindex e35cfc9714b7..507e366a295b 100644--- a/products/desktop/packages/ui/src/features/canvas/hooks/useTaskActivity.test.tsx+++ b/products/desktop/packages/ui/src/features/canvas/hooks/useTaskActivity.test.tsx@@ -2,10 +2,14 @@ import type {TaskActivity,TaskActivityPage,} from "@posthog/shared/domain-types";-import { QueryClient, QueryClientProvider } from "@tanstack/react-query";+import {+ focusManager,+ QueryClient,+ QueryClientProvider,+} from "@tanstack/react-query";import { act, renderHook, waitFor } from "@testing-library/react";import type { ReactNode } from "react";-import { beforeEach, describe, expect, it, vi } from "vitest";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";const mockClient = vi.hoisted(() => ({getTaskActivity: vi.fn(),@@ -50,6 +54,11 @@ describe("task activity hooks", () => {});});+ afterEach(() => {+ queryClient.clear();+ focusManager.setFocused(undefined);+ });+it("loads every activity page", async () => {mockClient.getTaskActivity.mockResolvedValueOnce({@@ -89,6 +98,51 @@ describe("task activity hooks", () => {});});+ it.each([+ [+ "the app regains focus",+ (): void => {+ act(() => focusManager.setFocused(false));+ act(() => focusManager.setFocused(true));+ },+ ],+ [+ "an Activity surface opens",+ (): void => {+ renderHook(() => useTaskActivity(), { wrapper });+ },+ ],+ ])("refreshes activity when %s", async (_name, refresh) => {+ mockClient.getTaskActivity+ .mockResolvedValueOnce({ results: [], unread_count: 0 })+ .mockResolvedValueOnce({+ results: [+ activity({+ id: "comment-activity-1",+ latest_comment_id: "comment-1",+ }),+ ],+ unread_count: 1,+ });++ const hook = renderHook(() => useTaskActivity(), { wrapper });+ await waitFor(() =>+ expect(mockClient.getTaskActivity).toHaveBeenCalledOnce(),+ );+ expect(hook.result.current.items).toEqual([]);++ refresh();++ await waitFor(() =>+ expect(hook.result.current.items[0]).toMatchObject({+ id: "comment-activity-1",+ commentId: "comment-1",+ }),+ );+ expect(mockClient.getTaskActivity).toHaveBeenCalledTimes(2);+ expect(hook.result.current.unreadCount).toBe(1);+ });+it("does not optimistically clear activity newer than the marker", async () => {const page: TaskActivityPage = {results: [activity({ activity_at: "2026-07-01T11:00:00Z" })],diff --git a/products/desktop/packages/ui/src/features/canvas/hooks/useTaskActivity.ts b/products/desktop/packages/ui/src/features/canvas/hooks/useTaskActivity.tsindex 0f219d499dc0..b3ae45202b75 100644--- a/products/desktop/packages/ui/src/features/canvas/hooks/useTaskActivity.ts+++ b/products/desktop/packages/ui/src/features/canvas/hooks/useTaskActivity.ts@@ -11,6 +11,8 @@ import { TASK_ACTIVITY_QUERY_KEY } from "../task-activity/taskActivityQuery";export { TASK_ACTIVITY_QUERY_KEY } from "../task-activity/taskActivityQuery";+const TASK_ACTIVITY_REFETCH_INTERVAL_MS = 60_000;+/*** Task lifecycle and comment activity for the current user, newest first. Task* lifecycle rows collapse per task while comment notifications remain separate.@@ -40,7 +42,10 @@ export function useTaskActivity(options?: { enabled?: boolean }): {? { before: page.next_before, beforeId: page.next_before_id }: undefined,enabled: !!client && (options?.enabled ?? true),- staleTime: Number.POSITIVE_INFINITY,+ staleTime: TASK_ACTIVITY_REFETCH_INTERVAL_MS,+ refetchInterval: TASK_ACTIVITY_REFETCH_INTERVAL_MS,+ refetchOnMount: "always",+ refetchOnWindowFocus: "always",meta: AUTH_SCOPED_QUERY_META,});const items = useMemo(