liveblocks
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "liveblocks":https://skillpi.com/zh/skills/deepskill-ee069812ea56cc422dbf389d17f07d1c38a2dac3ca766b87d08de16fdc813346。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
Liveblocks:为 Web 应用添加实时协作功能的专家级指导。适用于使用 Liveblocks 的 React 钩子和 API 实现实时光标、在线状态指示、协同编辑、评论或通知等实时协作场景。
介绍来源: third_party · TerminalSkills · 1.0.0 参考来源
SkillPi 解读
- 能完成的任务
- 翻译待完成,请参阅来源文档。
- 软件、账号及付费要求
- 翻译待完成,请参阅来源文档。
- 实测状态
- 未测试
文件浏览
Frontmatter
name: liveblocks
description: Expert guidance for Liveblocks, the platform for adding real-time collaboration features to web applications. Helps developers implement live cursors, presence indicators, collaborative editing, comments, and notifications using Liveblocks' React hooks and APIs.
license: Apache-2.0
compatibility: No special requirements
metadata:
author: terminal-skills
version: 1.0.0
category: development
tags:
- real-time
- collaboration
- multiplayer
- presence
- cursorsLiveblocks — Real-Time Collaboration SDK
Overview
Liveblocks, the platform for adding real-time collaboration features to web applications. Helps developers implement live cursors, presence indicators, collaborative editing, comments, and notifications using Liveblocks' React hooks and APIs.
Instructions
Room Setup and Presence
Configure a collaborative room with user presence tracking:
// src/liveblocks.config.ts — Liveblocks type configuration
import { createClient } from "@liveblocks/client";
import { createRoomContext, createLiveblocksContext } from "@liveblocks/react";
const client = createClient({
publicApiKey: process.env.NEXT_PUBLIC_LIVEBLOCKS_PUBLIC_KEY!,
// Or use auth endpoint for production (recommended)
// authEndpoint: "/api/liveblocks-auth",
});
// Define types for your collaborative data
type Presence = {
cursor: { x: number; y: number } | null; // User's cursor position
selectedId: string | null; // Currently selected element
name: string; // Display name
color: string; // Avatar/cursor color
};
type Storage = {
shapes: LiveList<Shape>; // Shared canvas shapes
document: LiveObject<DocumentState>; // Shared document state
};
type UserMeta = {
id: string;
info: { name: string; avatar: string; color: string };
};
export const {
RoomProvider,
useMyPresence,
useOthers,
useStorage,
useMutation,
useSelf,
} = createRoomContext<Presence, Storage, UserMeta>(client);
Live Cursors
Show other users' cursor positions in real time:
// src/components/LiveCursors.tsx — Display cursors of all connected users
import { useOthers, useMyPresence } from "../liveblocks.config";
import { useCallback, useEffect } from "react";
export function LiveCursors() {
const others = useOthers();
const [myPresence, updateMyPresence] = useMyPresence();
// Track cursor movement and broadcast to other users
const handlePointerMove = useCallback(
(e: React.PointerEvent) => {
updateMyPresence({
cursor: { x: e.clientX, y: e.clientY },
});
},
[updateMyPresence]
);
const handlePointerLeave = useCallback(() => {
updateMyPresence({ cursor: null });
}, [updateMyPresence]);
return (
<div
onPointerMove={handlePointerMove}
onPointerLeave={handlePointerLeave}
style={{ position: "relative", width: "100%", height: "100vh" }}
>
{/* Render other users' cursors */}
{others.map(({ connectionId, presence, info }) => {
if (!presence.cursor) return null;
return (
<Cursor
key={connectionId}
x={presence.cursor.x}
y={presence.cursor.y}
name={info?.name ?? "Anonymous"}
color={info?.color ?? "#000"}
/>
);
})}
</div>
);
}
function Cursor({ x, y, name, color }: { x: number; y: number; name: string; color: string }) {
return (
<div style={{ position: "absolute", left: x, top: y, pointerEvents: "none" }}>
{/* SVG cursor icon */}
<svg width="24" height="24" viewBox="0 0 24 24" fill={color}>
<path d="M5 3l14 8-6 2-2 6z" />
</svg>
{/* Name label */}
<span style={{
backgroundColor: color,
color: "white",
padding: "2px 8px",
borderRadius: "4px",
fontSize: "12px",
whiteSpace: "nowrap",
}}>
{name}
</span>
</div>
);
}
Collaborative Storage
Shared data structures that sync across all users:
// src/components/CollaborativeCanvas.tsx — Shared canvas with conflict-free updates
import { useStorage, useMutation } from "../liveblocks.config";
import { LiveList, LiveObject } from "@liveblocks/client";
type Shape = {
id: string;
type: "rectangle" | "circle" | "text";
x: number;
y: number;
width: number;
height: number;
fill: string;
};
export function CollaborativeCanvas() {
// useStorage reads from the shared room storage (synced via CRDT)
const shapes = useStorage((root) => root.shapes);
// useMutation creates a function that can modify shared storage
// Mutations are atomic and conflict-free — two users can edit simultaneously
const addShape = useMutation(({ storage }, shape: Shape) => {
const shapes = storage.get("shapes");
shapes.push(new LiveObject(shape));
}, []);
const moveShape = useMutation(({ storage }, id: string, x: number, y: number) => {
const shapes = storage.get("shapes");
const shape = shapes.find((s) => s.get("id") === id);
if (shape) {
shape.set("x", x); // Only the changed field syncs — bandwidth efficient
shape.set("y", y);
}
}, []);
const deleteShape = useMutation(({ storage }, id: string) => {
const shapes = storage.get("shapes");
const index = shapes.findIndex((s) => s.get("id") === id);
if (index !== -1) shapes.delete(index);
}, []);
return (
<canvas>
{shapes?.map((shape) => (
<CanvasShape
key={shape.id}
shape={shape}
onMove={(x, y) => moveShape(shape.id, x, y)}
onDelete={() => deleteShape(shape.id)}
/>
))}
</canvas>
);
}
Comments and Threads
Add comment threads to any part of your application:
// src/components/Comments.tsx — Inline comments on document elements
import { useThreads, useCreateThread, useCreateComment } from "@liveblocks/react/suspense";
export function CommentsSidebar({ elementId }: { elementId: string }) {
// Fetch all comment threads for this room
const { threads } = useThreads();
const createThread = useCreateThread();
const createComment = useCreateComment();
// Filter threads attached to the selected element
const elementThreads = threads.filter(
(thread) => thread.metadata.elementId === elementId
);
const handleNewThread = (body: string) => {
createThread({
body: { version: 1, content: [{ type: "paragraph", children: [{ text: body }] }] },
metadata: { elementId, resolved: false },
});
};
return (
<div className="comments-sidebar">
<h3>Comments</h3>
{elementThreads.map((thread) => (
<ThreadView
key={thread.id}
thread={thread}
onReply={(body) => createComment({ threadId: thread.id, body })}
/>
))}
<NewThreadForm onSubmit={handleNewThread} />
</div>
);
}
Authentication Endpoint
Secure room access with token-based auth:
// app/api/liveblocks-auth/route.ts — Next.js auth endpoint
import { Liveblocks } from "@liveblocks/node";
import { NextRequest, NextResponse } from "next/server";
import { getSession } from "@/lib/auth";
const liveblocks = new Liveblocks({
secret: process.env.LIVEBLOCKS_SECRET_KEY!,
});
export async function POST(request: NextRequest) {
const session = await getSession();
if (!session?.user) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
// Prepare Liveblocks session with user identity
const liveblocksSession = liveblocks.prepareSession(session.user.id, {
userInfo: {
name: session.user.name,
avatar: session.user.image,
color: generateColor(session.user.id), // Deterministic color from user ID
},
});
// Grant access to specific rooms based on your authorization logic
const { room } = await request.json();
const hasAccess = await checkRoomAccess(session.user.id, room);
if (hasAccess) {
liveblocksSession.allow(room, liveblocksSession.FULL_ACCESS);
}
const { status, body } = await liveblocksSession.authorize();
return new NextResponse(body, { status });
}
Installation
# Core packages
npm install @liveblocks/client @liveblocks/react
# For Next.js with comments and notifications
npm install @liveblocks/node @liveblocks/react-ui
# Yjs integration for text editing
npm install @liveblocks/yjs yjs
Examples
Example 1: Setting up Liveblocks with a custom configuration
User request:
I just installed Liveblocks. Help me configure it for my TypeScript + React workflow with my preferred keybindings.
The agent creates the configuration file with TypeScript-aware settings, configures relevant plugins/extensions for React development, sets up keyboard shortcuts matching the user's preferences, and verifies the setup works correctly.
Example 2: Extending Liveblocks with custom functionality
User request:
I want to add a custom live cursors to Liveblocks. How do I build one?
The agent scaffolds the extension/plugin project, implements the core functionality following Liveblocks's API patterns, adds configuration options, and provides testing instructions to verify it works end-to-end.
Guidelines
- Use auth endpoint in production — Public API keys are fine for dev; production needs proper authentication
- Type your presence and storage — TypeScript generics prevent runtime errors in collaborative data
- Granular mutations — Update individual fields, not entire objects; Liveblocks only syncs what changed
- Throttle presence updates — Cursor movement fires constantly; throttle to 50-100ms intervals
- Handle offline gracefully — Liveblocks queues changes offline; show a connection status indicator
- Room naming convention — Use predictable patterns like
project:{projectId}:document:{docId} - Clean up storage — Delete rooms when projects are archived; storage persists indefinitely
- Test with multiple tabs — Open your app in 2-3 tabs during development to verify real-time sync
当前收录版本
1.0.0
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供 Liveblocks 实时协作功能的完整开发指导
- 覆盖光标、在线状态、协同编辑、评论等核心场景
- 面向开发者群体,实用价值明确
亮点
- 触发词精准覆盖 Liveblocks 相关技术场景
- description 完整且位置正确
- 边界清晰,不易与其他 Skill 混淆
待提升项
-
缺少 When to Use 显式章节 原报告严重程度:轻微
文档内容隐含使用场景但未明确标出 When to Use 章节
改进建议:建议添加显式的 When to Use 章节以提升可读性
亮点
- Phase 划分清晰,从配置到实现逐步展开
- 包含完整端到端代码示例
- frontmatter 完整,单文件结构合理
待提升项
-
网络错误重试机制未覆盖 原报告严重程度:轻微
未提及网络中断时的重试策略和错误恢复机制
改进建议:建议补充网络错误处理和重试机制说明
亮点
- 工具来源明确,均为官方 Liveblocks 包
- TypeScript 类型定义完整,参数使用规范
- 包含认证失败处理和离线状态提示建议
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
-
安装或获取外部依赖
使用官方来源并锁定版本,在隔离环境检查安装脚本。当前文档检查不覆盖后续下载的代码。
主文档提及 · 第 293, 296, 299 行
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
翻译待完成,请参阅来源文档。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。