import { broadcastQueryClient } from "@tanstack/query-broadcast-client-experimental"; import type { QueryClient } from "@tanstack/react-query"; /** Same-origin channel name for cross-tab QueryClient sync. */ export const QUERY_BROADCAST_CHANNEL = "seahaven-admin-query"; /** * Syncs QueryClient cache (invalidations + data) across browser tabs via BroadcastChannel. * No-op outside the browser and during Vitest runs. */ export function setupQueryBroadcast(queryClient: QueryClient): void { if (typeof window === "undefined") return; if (import.meta.env.MODE === "test") return; broadcastQueryClient({ queryClient, broadcastChannel: QUERY_BROADCAST_CHANNEL, }); }