invalidate-task-lists.ts1016 BView on GitHub
import { getBrowserQueryClient } from '@/lib/browser-query-client';

/**
 * tRPC's tanstack query key for `userTasks.listUserTasks`, without an input — TanStack matches by
 * prefix, so this covers every variant the surfaces query (todo / done, per-scope limits, …).
 */
const TASK_LIST_QUERY_KEY = [['userTasks', 'listUserTasks']];

/**
 * Marks the cached task lists stale after the AGENT changed a task server-side.
 *
 * The list surfaces render from the tasks slice, which is hydrated from these queries — so a live
 * store patch alone survives only until the next mount, where a still-fresh cached response (1 min
 * staleTime) rehydrates the slice back to the pre-change row. That's how a task could visibly lose
 * the draft it had just produced. The change is already persisted server-side; this just stops the
 * client from serving the version from before it.
 */
export function invalidateTaskLists(): void {
  void getBrowserQueryClient()?.invalidateQueries({ queryKey=[redacted] });
}