tab-sync-lite

One state. Every tab. One line.

Log out in one tab and every tab logs out. Sync Zustand, Redux, signals or useState across open tabs, and new tabs start with the current state. No server, any framework.

$npm i tab-sync-lite
Try it live
  • 0.5 kB gzipped
  • 0 dependencies
  • v0.1.0
  • MIT
  • Chrome · Edge · Firefox · Safari 15.4+
2 tabs · 1 store
Live · click a tab0 messages · 0 servers
01Try it

Click in one tab. Watch the other.

Each frame below is its own page with its own store, like two browser tabs. Add to the cart, switch the theme or log out, and the other one follows. So do the tabs in the hero.

Tab ATab B

Each change is one message. Tabs never send it back.

Open a real new tab ↗
Channel · tab-sync-lite:demo Newest first
Waiting for a change…
Messages: 0 Replies to new tabs: 0 Echoes: 0
02Why

BroadcastChannel sends. This keeps tabs in step.

The browser can already pass messages between tabs. What it doesn't do is plug into your store, stop the echo when a tab applies a change, or tell a tab that just opened what everyone else already knows.

  • One line per store

    Anything with get, set and subscribe. Zustand fits as is.

  • New tabs catch up

    A new tab asks the open ones and starts with their state.

  • No echo loops

    A tab never sends back a change it just received.

  • Any framework

    React hook included. Vue, Svelte, Angular, none.

  • Actions stay put

    State travels as JSON, so functions stay in each tab.

  • Tiny

    About 0.5 kB gzipped, typed, zero dependencies.

03Use

Name it. Hand it your store.

Every tab that syncs a store under the same name shares it. Call it once per store. It returns a function that stops syncing.

import { tabsync } from 'tab-sync-lite';

const stop = tabsync('cart', {
  get: store.getState,
  set: store.setState,
  subscribe: store.subscribe,
});

Tabs of the same site (same origin) only. Nothing leaves the browser.

04Frameworks

Your store, everywhere.

Wrap the state you already have. Stop syncing when it goes away.