Cross-Tab Sync
Syncraft Labs automatically synchronizes state across browser tabs using the BroadcastChannel API. When a user updates state in one tab, all other tabs with the same store key are updated instantly — no server round-trip required.
How It Works
Tab 1 Tab 2┌─────────────────────┐ ┌─────────────────────┐│ useSync("cart") │ │ useSync("cart") ││ update(draft => { │ │ ││ draft.items.push │ │ ││ }) │ │ ││ │ │ │ ││ ▼ │ │ ││ 1. Memory update │ │ ││ 2. Notify subs │ │ ││ 3. ──BroadcastChannel──────────────▶ │ 4. Receive message ││ 4. IndexedDB write │ │ 5. Update memory ││ 5. Append outbox │ │ 6. Notify subs │└─────────────────────┘ └─────────────────────┘Step-by-Step
- Tab 1 calls
update()— memory is updated immediately - Tab 1 notifies its own subscribers (UI re-renders)
- Tab 1 posts a
SYNCRAFT_STATE_UPDATEmessage via BroadcastChannel - Tab 2 receives the message on the channel named
syncraft-{storageKey} - Tab 2 updates its in-memory state with the received snapshot
- Tab 2 notifies its own subscribers
- Tab 2 UI re-renders with the new state
Behavior Details
- Zero network calls: Cross-tab sync uses pure browser inter-process communication. No network traffic is generated.
- Same origin requirement: BroadcastChannel only broadcasts across tabs sharing the exact same protocol, domain, and port (Same-Origin Policy).
- Outbox draining: Only the tab making the edit appends to the outbox queue. Secondary tabs receive the updated state snapshot so their local UI remains in sync without creating duplicate outbox entries.