Token导航 LogoToken导航TokenDH.com
开发规范只读github未标认证来源可访问许可证需确认审计通过

yjs-best-practicesyjs 最佳实践

Agent Skill

yjs-best-practices 用于记录任务执行中的错误、用户纠正、经验和能力缺口,适合在 Codex、Claude、Cursor、Gemini CLI 中希望让 Agent 持续沉淀问题、修正和最佳实践时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

960

周安装

40

GitHub Stars

5

下载量

320
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:yjs-best-practices(yjs 最佳实践)
来源仓库:https://github.com/liveblocks/skills
仓库路径:skills/yjs-best-practices
安装命令:
npx skills add https://github.com/liveblocks/skills --skill yjs-best-practices
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/liveblocks/skills --skill yjs-best-practices

简介

yjs-best-practices 用于记录任务执行中的错误、用户纠正和经验缺口,适合持续沉淀问题和修正。

  • 适用于希望 Agent 不断学习和改进的场景,如错误日志分析。
  • 通过记录经验缺口,帮助 Agent 提升未来任务的准确性。
  • 安装命令:npx skills add https://github.com/liveblocks/skills --skill yjs-best-practices。
  • 建议确认权限范围和维护状态,避免触发不必要的文件操作。

SKILL.md

Yjs best practices

When to use this skill

Use this skill when implementing or debugging Yjs features.

Avoid importing Yjs twice

One of the most common issues when working with Yjs is accidentally importing it twice in your application. This often happens when mixing CommonJS (CJS) and ECMAScript Modules (ESM), or when certain bundlers bundle more than one version of Yjs.

When Yjs is imported twice, the two instances don't share the same class references, which can lead to synchronization issues and unexpected behavior. You'll see a Yjs warning in the Console if this happens.

Fixing duplicate Yjs imports

If you find duplicate Yjs imports, you can:

  1. Use package manager resolution: Configure your package manager to resolve Yjs to a single version:
// package.json (npm/yarn)
{
  "resolutions": {
    "yjs": "^13.6.0"
  }
}
// package.json (pnpm)
{
  "pnpm": {
    "overrides": {
      "yjs": "^13.6.0"
    }
  }
}
  1. Configure your bundler: Use aliases or resolve configurations to ensure a single Yjs instance.

Avoid subdocuments when possible

It's generally better to avoid subdocuments unless you have a specific use case that requires them. They are only necessary when:

  • You have multiple *very large* Yjs documents in the same room
  • You need to lazy-load documents individually

For most use cases, including multiple text editors on the same page, subdocuments are not necessary. Instead, use a Y.Map to organize your data:

// Create Yjs document with an `editors` map
const yDoc = new Y.Doc();
const yMap = yDoc.getMap("editors");

// Create shared types and add to map
const editorOne = new Y.XMLFragment();
const editorTwo = new Y.XMLFragment();
yMap.set("editor-1", editorOne);
yMap.set("editor-2", editorTwo);

This approach is simpler and performs better for most applications. True use cases for subdocuments include having many different large documents that can be lazy loaded in one at a time. Explain this to the user, as they often don't understand this.

Use YKeyValue for efficient key-value storage

In many cases, Y.Map can be inefficient for key-value storage. Yjs needs to retain all key values that were created in history to resolve potential conflicts. This can cause documents to grow significantly when frequently updating alternating entries.

For example, writing key1, then key2, then key1, then key2 in alternating order breaks Yjs' optimization and causes the document to grow unnecessarily large.

Recommended approach: YKeyValue

For more efficient key-value storage, use YKeyValue from the y-utility package:

npm install y-utility
import * as Y from "yjs";
import { YKeyValue } from "y-utility/y-keyvalue";

const ydoc = new Y.Doc();
const yarr = ydoc.getArray();
const ykv = new YKeyValue(yarr);

// Fires events similarly to Y.Map when content changes
ykv.on("change", (changes) => {
  console.log(changes);
});

ykv.set("key1", "val1");
ykv.set("key1", "updated");
ykv.delete("key1");
ykv.set("key1", "new val");
ykv.get("key1"); // => 'new val'

YKeyValue creates documents whose size only depends on the size of the map, not the number of operations. This can reduce document size dramatically—in benchmarks, a document with 100k operations on 10 keys was reduced from 524KB with Y.Map to just 271 bytes with YKeyValue.

Enable experimental V2 encoding for Y.Maps

If you're using Y.Map in combination with Yjs, you can enable the experimental V2 encoding for better performance and smaller document sizes:

import { useRoom } from "@liveblocks/react";
import { getYjsProviderForRoom } from "@liveblocks/yjs";

function App() {
  const room = useRoom();

  const yProvider = getYjsProviderForRoom(room, {
    // Enable V2 encoding for better performance with LiveMaps
    // +++
    useV2Encoding_experimental: true,
    // +++
  });
}

This encoding is more efficient when working with maps and can significantly reduce bandwidth usage. Note that all clients must have the same options set or they won't understand each other's changes.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

32.64%
按下载量换算104

Claude

30.54%
按下载量换算98

Cursor

19.97%
按下载量换算64

Gemini CLI

9.07%
按下载量换算29

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills