API reference > @kontsedal/olas-cross-tab > crossTabPlugin
crossTabPlugin() function
Cross-tab cache sync over BroadcastChannel. Mirrors writes and invalidations of opted-in queries across tabs of the same origin.
const userQuery = defineQuery({ id: 'users/detail', …, meta: { crossTab: true } })
createRoot(app, {
deps,
queries: queryEngine(),
plugins: [crossTabPlugin({ channelName: 'my-app/cache/v1' })],
})Only queries with meta: { crossTab: true } sync, on both the send and the receive side. That covers infinite queries: their pages travel with theirpageParams, so the receiving tab keeps paging from them. Page arrays can be large, and maxPayloadBytes warns about them. Fetches and hydration are a per-tab concern — every tab runs its own fetcher — so they never cross.
**Server safety.** Without a channelFactory, the plugin opens a channel only in a browser tab or a web worker. On a Node, Bun or Deno server, and where BroadcastChannel is not defined, it installs no hooks and the root boots with cross-tab off. A server's BroadcastChannel reaches every root in the process, so per-request roots would otherwise read each other's writes. A channelFactory opens a channel wherever it returns one.
**Non-cloneable data.** BroadcastChannel uses structured clone. Cache data containing a function or a symbol throws aDataCloneError at postMessage. The plugin catches it, callsonWarn(...), and drops the message — the sender's cache is unaffected. A class instance does not throw: it arrives as a plain object, without its prototype.
Signature:
export declare function crossTabPlugin(options: CrossTabOptions): OlasPlugin;Parameters
Parameter | Type | Description |
|---|---|---|
options |
Returns: