yjs-crdt

Domain-enhanced guidance for building collaborative features with Yjs CRDT, including architecture patterns, provider choices, and operational troubleshooting.

Nameyjs-crdt
Version1.0.0
Authorseekthought
Tagscrdt yjs collaboration real-time citado

安装

skillctl install -r skillhub yjs-crdt

Yjs CRDT Domain Skill

This skill helps an agent design, implement, and debug collaborative features using Yjs with production-oriented defaults.

When to Use This Skill

Use this skill when tasks include any of the following:

What This Skill Provides

Recommended Execution Flow

  1. Clarify collaboration scope: text-only vs rich schema, single doc vs multi-doc workspace.
  2. Select shared types and schema boundaries (Y.Map, Y.Array, Y.Text, nested types).
  3. Choose transport provider and room strategy.
  4. Implement initial sync using state vectors and incremental update propagation.
  5. Add awareness (presence/cursors) separately from persisted content.
  6. Add persistence/recovery strategy and compaction/GC policy.
  7. Validate idempotency and out-of-order update safety.

Architecture Defaults

1) Data Model

2) Sync Strategy

3) Provider Strategy

Copy-Ready API Patterns

Basic document + shared types

import * as Y from "yjs";

const ydoc = new Y.Doc();
const ymeta = ydoc.getMap("meta");
const ytext = ydoc.getText("content");

ymeta.set("title", "Untitled");
ytext.insert(0, "Hello collaborative world");

Incremental update replication

import * as Y from "yjs";

const docA = new Y.Doc();
const docB = new Y.Doc();

docA.on("update", (update) => Y.applyUpdate(docB, update));
docB.on("update", (update) => Y.applyUpdate(docA, update));

Efficient initial sync using state vector

import * as Y from "yjs";

const svA = Y.encodeStateVector(docA);
const svB = Y.encodeStateVector(docB);

const diffToB = Y.encodeStateAsUpdate(docA, svB);
const diffToA = Y.encodeStateAsUpdate(docB, svA);

Y.applyUpdate(docB, diffToB);
Y.applyUpdate(docA, diffToA);

Origin-based loop prevention in custom providers

import * as Y from "yjs";

class BridgeProvider {
  constructor(private ydoc: Y.Doc) {
    this.ydoc.on("update", (update, origin) => {
      if (origin === this) return;
      this.sendToNetwork(update);
    });
  }

  onRemoteUpdate(update: Uint8Array) {
    Y.applyUpdate(this.ydoc, update, this);
  }

  sendToNetwork(update: Uint8Array) {
    // transport-specific implementation
  }
}

Edge Cases and Diagnostics

Deliverable Checklist (for agents)

Local Reference Index

Use local resources for fast retrieval:

Source Provenance

This skill is aligned with public official sources from Yjs docs and official repositories.