"use client"; import { QueryClient } from "@tanstack/react-query"; import { ApiError } from "./api"; import { DEFAULT_STALE_TIME_MS } from "./constants"; /** * Singleton-style QueryClient factory. Created in the root layout's * QueryClientProvider (client component boundary); a module-level instance * would leak across SSR requests in dev hot reloads. * * Policy: server state (pages, blocks, databases, records, search, * notifications) is TanStack Query's job; Zustand owns editor/UI state only * (ARCHITECTURE.md ยง2). */ export function makeQueryClient(): QueryClient { return new QueryClient({ defaultOptions: { queries: { staleTime: DEFAULT_STALE_TIME_MS, retry: (failureCount, error) => { // Never retry typed API errors (4xx/5xx with a stable code); // retry transient network failures once. if (error instanceof ApiError) return false; return failureCount < 1; }, refetchOnWindowFocus: true }, mutations: { retry: false } } }); }