diff --git a/apps/code/src/renderer/features/tasks/hooks/taskListQueryOptions.ts b/apps/code/src/renderer/features/tasks/hooks/taskListQueryOptions.ts new file mode 100644 index 000000000..796c39034 --- /dev/null +++ b/apps/code/src/renderer/features/tasks/hooks/taskListQueryOptions.ts @@ -0,0 +1,10 @@ +/** + * Shared options for the three task-list queries (tasks, summaries, + * slack tasks). Force a refetch on return-to-focus regardless of + * staleness — the global `staleTime` is 5 min, so + * `refetchOnWindowFocus: true` would silently skip the refetch in the + * exact window we care about (laptop opened after a short walk). + */ +export const TASK_LIST_QUERY_OPTIONS = { + refetchOnWindowFocus: "always" as const, +}; diff --git a/apps/code/src/renderer/features/tasks/hooks/useTasks.ts b/apps/code/src/renderer/features/tasks/hooks/useTasks.ts index 9643f8ccf..04142501a 100644 --- a/apps/code/src/renderer/features/tasks/hooks/useTasks.ts +++ b/apps/code/src/renderer/features/tasks/hooks/useTasks.ts @@ -1,4 +1,5 @@ import { pinnedTasksApi } from "@features/sidebar/hooks/usePinnedTasks"; +import { TASK_LIST_QUERY_OPTIONS } from "@features/tasks/hooks/taskListQueryOptions"; import { workspaceApi } from "@features/workspace/hooks/useWorkspace"; import { useAuthenticatedMutation } from "@hooks/useAuthenticatedMutation"; import { useAuthenticatedQuery } from "@hooks/useAuthenticatedQuery"; @@ -14,8 +15,6 @@ import { useCallback } from "react"; const log = logger.scope("tasks"); -const TASK_LIST_POLL_INTERVAL_MS = 30_000; - const taskKeys = { all: ["tasks"] as const, lists: () => [...taskKeys.all, "list"] as const, @@ -53,7 +52,7 @@ export function useTasks( }) as unknown as Promise, { enabled: (options?.enabled ?? true) && !!currentUser?.id, - refetchInterval: TASK_LIST_POLL_INTERVAL_MS, + ...TASK_LIST_QUERY_OPTIONS, }, ); } @@ -67,7 +66,7 @@ export function useTaskSummaries( (client) => client.getTaskSummaries(ids), { enabled: (options?.enabled ?? true) && ids.length > 0, - refetchInterval: TASK_LIST_POLL_INTERVAL_MS, + ...TASK_LIST_QUERY_OPTIONS, placeholderData: keepPreviousData, }, ); @@ -91,7 +90,7 @@ export function useSlackTasks(options?: { }) as unknown as Promise, { enabled: options?.enabled ?? true, - refetchInterval: TASK_LIST_POLL_INTERVAL_MS, + ...TASK_LIST_QUERY_OPTIONS, }, ); } diff --git a/apps/code/src/renderer/stores/rendererWindowFocusStore.ts b/apps/code/src/renderer/stores/rendererWindowFocusStore.ts index e9b85c4ea..22135b927 100644 --- a/apps/code/src/renderer/stores/rendererWindowFocusStore.ts +++ b/apps/code/src/renderer/stores/rendererWindowFocusStore.ts @@ -2,7 +2,8 @@ import { create } from "zustand"; /** * True when the renderer document is visible and the window has OS focus. - * Used to pause inbox polling when the Electron window is in the background. + * Used to pause polling-style queries (inbox, task list, etc.) when the + * Electron window is in the background. */ function computeWindowFocused(): boolean { if (typeof document === "undefined") {