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 - engine
- Yjs, behind a neutral adapterPlus a small last-writer-wins engine for scalars.
- transports
- tabs, WebSocket, your relay
createSyncServerfor Node and Bun. - offline
- IndexedDB persistence
- inbound frame
- 59 nsWebSocket frame intake on the transport's fast path, overnight run.
- 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 →Multiplayer and offline without rewriting your app.
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.Concurrent edits are kept
syncedTextandsyncedListmerge 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.Offline, then caught up
persistViaIndexedDBkeeps every edit locally; the WebSocket transport reconnects and reconciles state vectors when the network returns.ws.synced()tells you when you're caught up.A relay you can secure
createSyncServerkeeps one authoritative document per room, and runs yourauthorizehook before any data moves. From the next release it also closes cross-site browser upgrades before that hook even runs.
Collaboration is an import, not a rewrite.
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)} />
}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 Yjs + React?
Keep Yjs. Drop the bridge code.
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)} />
}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)} />
}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.
- Draft the launch postLaptop
In sync.
- Draft the launch postLaptop
- Record the demoPhone
In sync.
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.
- inbound WebSocket framemeasuredper frame
- presence publish overhead, 1 peermeasured5.5 µs at 200 peers
- synced-text keystroke, 1k docmeasured72.8 µs at 10k, fragmented
Local-first, end to end.
syncedSignalandsyncedStoreone value, or a flat store of synced fields.syncedTextaSignal<string>overY.Textwith positionalinsertanddelete.syncedListaSignal<T[]>overY.Array; render with a keyed<For>.syncedAwarenesspresence and live cursors, never persisted.- Offline
persistViaIndexedDBwithwhenSynced. - Transports
connectViaBroadcastChannelacross tabs,connectViaWebSocketacross devices (auto-reconnect),connectYDocsin memory. - Relay server
createSyncServerfor Node and Bun, withauthorizeand attach-to-existing-server mode. - Seeds wait for the first sync an
initialvalue never overwrites a peer's real one. - Test double
FakeCrdtDocandconnectFakeDocsfor synchronous unit tests. - Native scalars
syncedSignalover aPyreonCrdtDoccompiles to iOS and Android (strings, numbers, booleans). Experimental.
Things to build with it.
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 }
}Three entries: bridge, engine, relay.
Every export has a reference page with its signature, an example and the mistakes people make with it.
- syncedSignal
- syncedStore
- PyreonCrdtDoc
- connectPyreonSync
- FakeCrdtDoc
- connectFakeDocs
- createNativeSyncHost
- createYjsDoc
- syncedText
- syncedList
- syncedAwareness
- persistViaIndexedDB
- connectViaWebSocket
- connectViaBroadcastChannel
- connectYDocs
- createSyncServer
- CrdtAdapter
- CrdtDoc
- CrdtMap
- SyncedSignal
- SyncedStore
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.
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