Skills2026年5月19日·1 分钟阅读

Yjs — High-Performance CRDT Framework for Real-Time Collaboration

A modular CRDT implementation that enables real-time collaborative editing in any application, with network-agnostic sync providers for WebSocket, WebRTC, and more.

Agent 就绪

先审查再安装

这个资产需要先审查。复制的指令会要求 Agent dry-run、列出写入项,确认后再继续。

Needs Confirmation · 66/100策略:需确认
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Quick Use
先审查命令
npx -y tokrepo@latest install fc153aa0-535b-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run,确认写入项后再运行此命令。

Introduction

Yjs is a high-performance CRDT (Conflict-free Replicated Data Type) framework written in JavaScript. It allows multiple users to edit the same data concurrently without conflicts. Yjs is editor-agnostic and works with Tiptap, ProseMirror, Monaco, CodeMirror, Quill, and many other editors.

What Yjs Does

  • Merges concurrent edits automatically without a central server
  • Provides shared data types: Text, Array, Map, and XML Fragment
  • Syncs state over WebSocket, WebRTC, or any custom transport
  • Supports offline editing with automatic reconciliation on reconnect
  • Tracks awareness (cursor positions, user presence) across peers

Architecture Overview

Yjs represents shared state as a document (Y.Doc) containing typed structures. Each edit is encoded as an update operation that can be applied in any order. The CRDT algorithm ensures all peers converge to the same state regardless of message ordering. Providers handle transport: y-websocket for client-server, y-webrtc for peer-to-peer, and y-indexeddb for local persistence.

Self-Hosting & Configuration

  • Install yjs and a provider (y-websocket, y-webrtc, or y-indexeddb)
  • Run the y-websocket server: HOST=localhost PORT=1234 npx y-websocket
  • Bind shared types to your editor using bindings (e.g., y-prosemirror, y-monaco)
  • Persist documents server-side with LevelDB or a custom storage adapter
  • Scale horizontally by partitioning documents across WebSocket server instances

Key Features

  • Sub-millisecond merge performance even with large documents
  • Works offline-first with sync on reconnect
  • Awareness protocol for live cursors and user presence
  • Undo/redo manager with per-user scope
  • Sub-document support for lazy loading parts of a large document

Comparison with Similar Tools

  • Automerge — Rust-based CRDT, better for structured data; Yjs is faster for text
  • ShareDB — OT-based, requires a central server; Yjs is decentralized
  • Liveblocks — managed service with CRDT under the hood; Yjs is self-hostable
  • Fluid Framework — Microsoft-backed, more opinionated architecture
  • Gun.js — decentralized database with eventual consistency, different use case

FAQ

Q: Which editors does Yjs support? A: Tiptap, ProseMirror, CodeMirror, Monaco, Quill, Slate, Lexical, and others via official or community bindings.

Q: Can Yjs work without a server? A: Yes, use y-webrtc for peer-to-peer sync or y-indexeddb for local-only persistence.

Q: How does conflict resolution work? A: Yjs uses CRDTs, so all concurrent edits are merged deterministically. No conflicts require manual resolution.

Q: How large can documents get? A: Yjs handles documents with millions of operations efficiently through incremental encoding and garbage collection.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产