mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 16:19:01 +00:00
19 lines
686 B
TypeScript
19 lines
686 B
TypeScript
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,
|
|
});
|
|
}
|