Zustand middleware for persisting and syncing state across browser tabs, windows, and iframes (same origin). Current stable version is 1.2.3, released regularly with a focus on reliability. It uses the Broadcast Channel API for instant cross-tab synchronization and localStorage (or sessionStorage/cookies) for persistence. Differentiators include sub-1kB size, full TypeScript support, fire-and-forget state updates optimized for single-user systems, and exclude/include filters for selective syncing. Alternatives like zustand's built-in persist middleware lack cross-tab sync out of the box.
npm install persist-and-syncVerified import paths — ran on the pinned version, not inferred.
Creates a Zustand store with persistNSync middleware; state is persisted to localStorage and synced across tabs.
Ensure all tabs/windows are on the same origin (protocol, host, port).
Use 'localStorage' (default) if you need persistence across browser restarts.
Replace 'regExpToIgnore: /pattern/' with 'exclude: [/pattern/]' in the options object.
For collaborative editing or multi-writer conflicts, consider a different sync strategy or backend.
Flatten nested state or create separate stores for subsets you want to filter.
Run 'npm install persist-and-sync' and ensure tsconfig.json includes 'node_modules' in 'typeRoots' or uses a bundler that resolves types.
Change to 'import { persistNSync } from 'persist-and-sync';'Use 'const { persistNSync } = require('persist-and-sync');'Serve the app via a local dev server (e.g., 'npx serve .' or use a framework dev server).