# @svelte-lean/query/tabs

> tabs(): one poller and one live connection per browser, invalidations and values shared across tabs.

Page: https://svelte-lean.vercel.app/query/api/tabs · Markdown: https://svelte-lean.vercel.app/query/api/tabs.md · Index: https://svelte-lean.vercel.app/llms.txt

tabs(): one tab polls each polled entry and holds the live connection (Web Locks); the others receive invalidations, changed values and live events over a BroadcastChannel, per scope and session.

> **Note** `./tabs` is experimental: the API can still change in a minor release. Stability per entry point: [Entry points](https://svelte-lean.vercel.app/query.md#entry-points).

## Import

`import`

```ts
import { tabs } from '@svelte-lean/query/tabs';
```

## Usage

`src/lib/api/modules.ts`

```ts
// src/lib/api/modules.ts
import { tabs } from '@svelte-lean/query/tabs';
import { session } from '$api/session.svelte';

// Tabs of the same user share one poller and one live connection; another login never hears them.
export const crossTab = tabs({
	session: () => (session.userId === null ? null : String(session.userId))
});
```

## Size

Production Vite builds of a small consumer entry, Svelte external. A marginal row is the bytes the entry adds over the row it names.

| Build | Over | gzip | brotli | Budget (gzip) |
| --- | --- | --- | --- | --- |
| `tabs (marginal)` | `query` | 3104 B | 2874 B | 3500 B |

Read from `packages/query/artifacts/size.json`. Every entry and its method: [Performance](https://svelte-lean.vercel.app/query/performance.md).

## Functions

One module; no call site changes.

### Exports

Runtime exports of the entry.

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| # `tabs` | `(init?: TabsInit) => Module` | – | Cross-tab coordination. Without BroadcastChannel or Web Locks every tab works alone. |

## Options

TabsInit, the argument of tabs().

### TabsInit

All optional.

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| # `name` | `string` | `'slq'` | Namespace of the channel and lock names. |
| # `session` | `() => string \| null` | – | Reactive partition beside the scope (a user id): tabs of another session never share. null: this tab works alone. |
| # `share` | `number \| false` | `16384` | Largest value (JSON text length) sent with a changed entry; above it the receiving tab refetches. false: never. |

## Guide

How to use it, with examples: [Realtime](https://svelte-lean.vercel.app/query/realtime.md). All entry points: [Svelte Lean Query](https://svelte-lean.vercel.app/query.md).
