Skip to content
@pyreon/sync
fundamentals · local-first

Same signal. Now it's multiplayer, and it works offline.

A synced value is still a signal, backed by a CRDT. Edits from other tabs, devices and people merge, survive offline and come back after a reload, and each remote change updates only the DOM that reads it. Yjs does the merging; a relay server with per-room auth is included.

bun add @pyreon/sync
Documentation
engine
Yjs, behind a neutral adapterPlus a small last-writer-wins engine for scalars.
transports
tabs, WebSocket, your relaycreateSyncServer for Node and Bun.
offline
IndexedDB persistence
inbound frame
59 nsWebSocket frame intake on the transport's fast path, overnight run.
Two devices edit offline and converge Schematic: a laptop and a phone share one synced list through a WebSocket relay. The phone goes offline and adds coffee, saved to IndexedDB; the laptop adds bread. When the phone reconnects, both edits merge through the relay and both lists show milk, eggs, bread and coffee. Then the two items are removed and the removal syncs too. SYNCEDSIGNAL · YJS CRDT · OFFLINE-FIRST laptop · online phone online offline milkeggs breadcoffee milkeggs bread coffee coffee 1 queued · IndexedDB relay WebSocketper-room auth both edits survive tabs, devices, people · a remote change updates only the DOM that reads it
  • 59 ns to take in an inbound WebSocket frame on the transport's fast path.BENCHMARKS.md §11 sync (Pyreon-only, no competitor), overnight run 2026-11-05
  • 3.8 µs per synced-text keystroke on a 1k document; 72.8 µs on a fragmented 10k one.BENCHMARKS.md §11 sync
  • 5.5 µs of signal-wrapper overhead per cursor publish in a 200-peer room (240 ns with one peer).BENCHMARKS.md §11 sync

synthetic · author-run · M3 Max · record of 2026-11-05

Every result, including where we lose →
why teams pick it

Multiplayer and offline without rewriting your app.

  1. It is still a signal

    Templates, effects and the compiler can't tell a synced signal from a local one. title() reads, title.set() writes, and only the text that shows the title updates when a peer changes it.

  2. Concurrent edits are kept

    syncedText and syncedList merge by position, so two people typing or adding cards at once both keep their work. Scalars are last-writer-wins, and the docs say so.

  3. Offline, then caught up

    persistViaIndexedDB keeps every edit locally; the WebSocket transport reconnects and reconciles state vectors when the network returns. ws.synced() tells you when you're caught up.

  4. A relay you can secure

    createSyncServer keeps one authoritative document per room, and runs your authorize hook before any data moves. From the next release it also closes cross-site browser upgrades before that hook even runs.

the difference

Collaboration is an import, not a rewrite.

a local signal

Lives in one tab and is gone on reload.

import { signal } from '@pyreon/reactivity'

const title = signal('Untitled') // one tab, gone on reload

function Title() {
  return <input value={title()} onInput={(e) => title.set(e.currentTarget.value)} />
}
a synced signal

Same reads, same writes, same component. Now shared, merged and stored offline.

import { syncedSignal } from '@pyreon/sync'
import { connectViaWebSocket, createYjsDoc, persistViaIndexedDB } from '@pyreon/sync/yjs'

const doc = createYjsDoc()
persistViaIndexedDB(doc, 'doc-42')
connectViaWebSocket(doc, 'wss://sync.example.com/doc-42')

const title = syncedSignal({ doc, key: 'title', initial: 'Untitled' })

function Title() {
  return <input value={title()} onInput={(e) => title.set(e.currentTarget.value)} />
}
coming from

Coming from Yjs + React?

Keep Yjs. Drop the bridge code.

Yjs + React
import { useSyncExternalStore } from 'react'
import * as Y from 'yjs'

const doc = new Y.Doc()
const meta = doc.getMap<string>('meta')
// + a provider (y-websocket, y-indexeddb) wired to `doc`

function useTitle() {
  return useSyncExternalStore(
    (onChange) => {
      meta.observe(onChange)
      return () => meta.unobserve(onChange)
    },
    () => meta.get('title') ?? 'Untitled',
  )
}

function Title() {
  const title = useTitle()
  return <input value={title} onChange={(e) => meta.set('title', e.target.value)} />
}
Pyreon

Same Yjs document underneath, so existing Yjs data and tooling still apply. syncedSignal replaces the observe / unobserve / snapshot bridge, and the transports and IndexedDB persistence are included.

import { syncedSignal } from '@pyreon/sync'
import { connectViaWebSocket, createYjsDoc, persistViaIndexedDB } from '@pyreon/sync/yjs'

const doc = createYjsDoc()
persistViaIndexedDB(doc, 'doc-42')
connectViaWebSocket(doc, 'wss://sync.example.com/doc-42')

const title = syncedSignal({ doc, key: 'title', initial: 'Untitled' })

function Title() {
  return <input value={title()} onInput={(e) => title.set(e.currentTarget.value)} />
}
try it

Two devices, one list. Go offline and back.

Add items on both devices, take one offline, keep editing, then reconnect. Both sets of changes survive.

Laptoponline
  • Draft the launch postLaptop

In sync.

Phoneonline
  • Draft the launch postLaptop
  • Record the demoPhone

In sync.

benchmarks

A synced keystroke in 3.8 µs. An inbound frame in 59 ns.

No head-to-head exists for sync, so these are our own throughput figures for the bridge between Yjs and your signals. The presence row is the overhead the signal wrapper adds over raw y-protocols.

Pyreon-only throughput (no competitor)Pyreonrival · lower is better
  • inbound WebSocket frame
    measuredper frame
  • presence publish overhead, 1 peer
    measured5.5 µs at 200 peers
  • synced-text keystroke, 1k doc
    measured72.8 µs at 10k, fragmented
Apple M3 Max · record of 2026-11-05 · overnight run, one run · author-run, syntheticFull method, every loss →
what's included

Local-first, end to end.

  • syncedSignal and syncedStore one value, or a flat store of synced fields.
  • syncedText a Signal<string> over Y.Text with positional insert and delete.
  • syncedList a Signal<T[]> over Y.Array; render with a keyed <For>.
  • syncedAwareness presence and live cursors, never persisted.
  • Offline persistViaIndexedDB with whenSynced.
  • Transports connectViaBroadcastChannel across tabs, connectViaWebSocket across devices (auto-reconnect), connectYDocs in memory.
  • Relay server createSyncServer for Node and Bun, with authorize and attach-to-existing-server mode.
  • Seeds wait for the first sync an initial value never overwrites a peer's real one.
  • Test double FakeCrdtDoc and connectFakeDocs for synchronous unit tests.
  • Native scalars syncedSignal over a PyreonCrdtDoc compiles to iOS and Android (strings, numbers, booleans). Experimental.
recipes

Things to build with it.

A shared board with a secured relay

Two clients on one room converge on the title and both cards; a client with a bad token never syncs.

// server.ts: Node or Bun
import { createSyncServer } from '@pyreon/sync/server'

const relay = await createSyncServer({
  port: 1234,
  authorize: ({ room, token }) => canEdit(room, token), // false → closed with 4401
})

import { syncedSignal } from '@pyreon/sync'
import { connectViaWebSocket, createYjsDoc, persistViaIndexedDB, syncedList } from '@pyreon/sync/yjs'

function openBoard(room: string, token: string) {
  const doc = createYjsDoc()
  persistViaIndexedDB(doc, room) // edits survive reloads and offline
  const ws = connectViaWebSocket(doc, `ws://localhost:1234/${room}?token=${token}`)

  const title = syncedSignal({ doc, key: 'title', initial: 'Untitled' }) // a signal
  const cards = syncedList<string>(doc, 'cards') // a Signal<string[]>, merged by position
  return { title, cards, ws }
}
api

Three entries: bridge, engine, relay.

Every export has a reference page with its signature, an example and the mistakes people make with it.

@pyreon/sync · 7
  • syncedSignal
  • syncedStore
  • PyreonCrdtDoc
  • connectPyreonSync
  • FakeCrdtDoc
  • connectFakeDocs
  • createNativeSyncHost
@pyreon/sync/yjs · 8
  • createYjsDoc
  • syncedText
  • syncedList
  • syncedAwareness
  • persistViaIndexedDB
  • connectViaWebSocket
  • connectViaBroadcastChannel
  • connectYDocs
@pyreon/sync/server · 1
  • createSyncServer
types · 5
  • CrdtAdapter
  • CrdtDoc
  • CrdtMap
  • SyncedSignal
  • SyncedStore
good to know

Good to know before you start.

CRDTs prevent lost updates, not conflicts

Scalar fields are last-writer-wins, and merged text can still read oddly when two people rewrite one sentence. Use syncedText for strings people edit together, and show presence.

Budget about 60 KB gzipped

Yjs, y-indexeddb, y-protocols and the WebSocket client come with the /yjs entry. It stays out of apps that never import it.

Write your authorize hook

Without one the relay accepts every connection and warns in the log, even in production. Whole-document CRDTs make per-field access hard: use one room per document.

Native covers scalars

On iOS and Android syncedSignal lowers; text, lists, presence and the Yjs transports stay web, and native cross-device transport is still being built.

questions

What people ask first.

Is this a new CRDT?

For text, lists and presence, no: it is Yjs. The package adds the signal bridge, transports, persistence and a relay. A small dependency-free last-writer-wins engine (PyreonCrdtDoc) exists for scalars, which is the part that compiles to native.

Do I need my own server?

Cross-tab sync needs none (BroadcastChannel). Across devices you need a relay; createSyncServer is one, and it can attach to your existing HTTP server.

Does the relay store documents?

No. It keeps an in-memory document per room so late joiners catch up. Durability lives in each client's IndexedDB, or in a store you add.

How do I test synced code?

With FakeCrdtDoc and connectFakeDocs, which are synchronous and need no engine. For offline-reconnect behaviour, use createYjsDoc with connectYDocs.

Ship multiplayer without a backend rewrite. Or much of a backend.

bun add @pyreon/sync
Read the sync guide