liveblocks-best-practices
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseLiveblocks best practices
Liveblocks最佳实践
When to use this skill
使用此技能的场景
Use this skill when implementing features using any Liveblocks packages, for
example
or . This
could be related to features like realtime multiplayer, commenting,
notifications, cursors, avatar stacks, AI, and more. This also includes
technologies like Liveblocks Storage, Yjs, Tiptap, BlockNote, Lexical, React
Flow, tldraw, and more.
@liveblocks/react@liveblocks/node当你使用任何Liveblocks包实现功能时,均可使用此技能,例如或。这可能涉及实时多人协作、评论、通知、光标、头像堆叠、AI等功能,也涵盖Liveblocks Storage、Yjs、Tiptap、BlockNote、Lexical、React Flow、tldraw等技术。
@liveblocks/react@liveblocks/nodeQuick reference
快速参考
A number of reference files are available in the directory. You
must read the list below, and load relevant files as needed. For example,
is available in the
file.
references/add-user-informationreferences/add-user-information.mdreferences/add-user-informationreferences/add-user-information.mdReferences
参考内容
- : Add user information to your application, such as name, avatar, color, and more. Users will no longer be anonymous. Useful for displaying user info in comments, comments mention suggestions, notifications, cursors, avatar stacks.
add-user-information - : Use agentic workflows to allow AI to collaborate like a human inside your Liveblocks application.
ai-as-a-collaborator - : Set up and troubleshoot chats with RAG, knowledge, custom components, tool calling, custom models. Different to AI as a collaborator, as it is NOT workflow based.
ai-chats-with-tools-knowledge-components - : Use a callback function to authenticate users, instead of passing a string to
auth-endpoint-callback. Useful for passing custom headers to your back end, and for preventing automatic reconnection when the token is invalid.authEndpoint - : Alternative method for authenticating users with their ID and info, best for very simple permissions.
authenticating-with-access-tokens - : Recommended method for authenticating users with their ID and info, best for complex permissions.
authenticating-with-id-tokens - : How to avoid rooms filling up with users.
avoid-hitting-user-limit-in-rooms - : Use organizations to create workspaces/tenants and compartmentalize resources, such as rooms, notifications, comment threads, and more. You can filter by organization when listing rooms and more.
compartmentalize-resources-with-organizations - : Build your own commenting composer (advanced use cases only).
create-custom-comment-composer - : Use Liveblocks Storage to build fully custom conflict-resolved multiplayer apps, like Figma, Pitch, Spline. Helpful for one-off realtime features too, like simple properties in a document.
create-custom-realtime-multiplayer - : Set up a styled toolbar, static or floating next to your selection, in Tiptap and Lexical.
create-custom-text-editor-toolbar - : Always create rooms yourself in production applications, setting permissions, organization, metadata.
create-rooms-manually - : Use slots to customize comments inside of threads, and their different parts.
customize-thread-components - : You can import CSS styling for dark mode themes.
dark-mode-styles - : Set up a local dev server, and use it for Continuous Integration (CI) and End-to-End (E2E) testing. Connect to your app not online.
develop-and-test-locally - : Inspect Liveblocks Storage, Yjs, presence, events, and connected users with DevTools extensions for Chrome, Firefox, Edge.
devtools-extension - : Override strings in default components, such as button values, tooltip text, error text, more. Also helpful for setting other languages.
edit-component-text-strings - : Prevent and fix stale-closure bugs with
exhaustive-deps-with-usemutationby configuring theuseMutationESLint rule.react-hooks/exhaustive-deps - : Handle problems joining rooms because of permissions, authentication, changed room IDs.
handling-connection-errors - : Handle problems caused by joining full rooms.
handling-full-rooms - : Handle errors caused by hooks and pre-built components.
handling-hook-and-component-errors - : Implement fallbacks and error messages when users have poor network conditions.
handling-unstable-connections - : Rarely useful, but helpful in specific SPA situations where you cannot navigate the page to log out.
log-out-of-liveblocks - : Use the Liveblocks React Flow package to create multiplayer diagrams with cursors and more.
multiplayer-react-flow - : Add multiple Tiptap or BlockNote editors to the same page. Optionally use Storage to hold their field IDs.
multiple-text-editors - : Give your text editors the illusion of a quicker load time.
offline-support-in-text-editors - : Add custom styles to the default components by overriding Liveblocks CSS variables.
override-css-variables - : Prevent unnecessary presence renders by using
performant-others-and-presence,useOtherConnectionIds,useOthersMapped, anduseOtherto update components only when necessary.shallow - : Prevent unnecessary storage renders by using
performant-storage-with-selectorsselectors anduseStorage.shallow - : Stop losing unsynched or unsaved changes.
prevent-unsaved-changes-being-lost - : Use primitives to create custom components or to merge components from your design system into Liveblocks UI.
primitive-component-parts - : A Liveblocks logo badge appears in the bottom right of the screen, this is how to remove it.
remove-liveblocks-branding - : Use
rendering-error-componentsto structure your app with error fallbacks.ErrorBoundary - : Use
rendering-loading-componentsto performantly structure your app with loading skeletons and spinners.ClientSideSuspense - : Send email notifications to users when they have unread comments. These comments are sent via webhooks, and are triggered when a user is mentioned, or has participated in a thread.
send-comment-notification-emails - : Make presence and storage run at a higher frame rate, appearing more smooth. Using this option, updates can be received more frequently.
smoother-realtime-updates - : You must read this when using any Liveblocks hooks. React suspense uses
suspense-vs-regular-hooksandErrorBoundarycomponents. Regular hooks useClientSideSuspensevalues.{ error, isLoading } - : Server-side rendering, starter kit extensions, initial content, unsaved changes, more.
tiptap-best-practices - : Trigger any kind of notification in your inbox, even those unrelated to commenting.
trigger-custom-notifications - : Always use TypeScript to type Liveblocks where available. Presence, others, user info, storage, metadata, room info, notifications activities, can all be automatically typed.
type-liveblocks-correctly - : Use URL params in room IDs to create rooms, and incorporate document titles in the URL.
url-params-in-room-id - : Import a ready-made emoji picker, or human-readable timestamps, durations, file sizes.
utility-components - : YKeyValue, subdocuments, V2 encoding, double imports, getYjsProviderForRoom. NOT relevant if you're using Tiptap, BlockNote, or Lexical.
yjs-best-practices - : Fix z-index problems by targeting portaled elements.
z-index-issues
- : 为你的应用添加用户信息,如姓名、头像、颜色等。用户将不再以匿名身份显示。适用于在评论、评论提及建议、通知、光标、头像堆叠中展示用户信息。
add-user-information - : 使用智能代理工作流,让AI能够像人类一样在你的Liveblocks应用内协同工作。
ai-as-a-collaborator - : 设置并调试带有RAG、知识库、自定义组件、工具调用、自定义模型的聊天功能。与AI协作者不同,此功能不基于工作流。
ai-chats-with-tools-knowledge-components - : 使用回调函数对用户进行身份验证,而非将字符串传递给
auth-endpoint-callback。适用于向后端传递自定义标头,以及在令牌无效时阻止自动重新连接。authEndpoint - : 使用访问令牌对用户及其信息进行身份验证的替代方法,非常适合简单权限场景。
authenticating-with-access-tokens - : 推荐的用户身份验证方法,适用于复杂权限场景,可验证用户ID及其信息。
authenticating-with-id-tokens - : 如何避免房间内用户数量达到上限。
avoid-hitting-user-limit-in-rooms - : 使用组织功能创建工作区/租户,并对资源进行划分,如房间、通知、评论线程等。你可以在列出房间时按组织筛选。
compartmentalize-resources-with-organizations - : 构建自定义评论编辑器(仅适用于高级场景)。
create-custom-comment-composer - : 使用Liveblocks Storage构建完全自定义的冲突解决型多人协作应用,例如Figma、Pitch、Spline。也适用于构建一次性实时功能,如文档中的简单属性。
create-custom-realtime-multiplayer - : 在Tiptap和Lexical中设置样式化工具栏,可以是静态工具栏,也可以是跟随选区浮动的工具栏。
create-custom-text-editor-toolbar - : 在生产环境中,请始终手动创建房间,并设置权限、组织、元数据。
create-rooms-manually - : 使用插槽自定义线程内的评论及其各个部分。
customize-thread-components - : 你可以导入暗模式主题的CSS样式。
dark-mode-styles - : 设置本地开发服务器,并将其用于持续集成(CI)和端到端(E2E)测试。无需在线即可连接到你的应用。
develop-and-test-locally - : 使用Chrome、Firefox、Edge的DevTools扩展,检查Liveblocks Storage、Yjs、在线状态、事件以及已连接用户。
devtools-extension - : 覆盖默认组件中的字符串,如按钮文本、提示框文本、错误文本等。也有助于设置其他语言。
edit-component-text-strings - : 通过配置
exhaustive-deps-with-usemutationESLint规则,预防并修复react-hooks/exhaustive-deps的闭包过期问题。useMutation - : 处理因权限、身份验证、房间ID变更导致的无法加入房间问题。
handling-connection-errors - : 处理因房间已满导致的问题。
handling-full-rooms - : 处理由钩子和预构建组件引发的错误。
handling-hook-and-component-errors - : 当用户网络状况不佳时,实现降级方案和错误提示。
handling-unstable-connections - : 很少用到,但在特定单页应用(SPA)场景下很有用,比如无法通过页面导航实现登出时。
log-out-of-liveblocks - : 使用Liveblocks React Flow包创建带有光标等功能的多人协作图表。
multiplayer-react-flow - : 在同一页面添加多个Tiptap或BlockNote编辑器。可选择使用Storage存储它们的字段ID。
multiple-text-editors - : 为文本编辑器提供更快加载的体验。
offline-support-in-text-editors - : 通过覆盖Liveblocks的CSS变量,为默认组件添加自定义样式。
override-css-variables - : 使用
performant-others-and-presence、useOtherConnectionIds、useOthersMapped和useOther,避免不必要的在线状态渲染,仅在必要时更新组件。shallow - : 使用
performant-storage-with-selectors选择器和useStorage,避免不必要的存储渲染。shallow - : 防止未同步或未保存的更改丢失。
prevent-unsaved-changes-being-lost - : 使用基础组件创建自定义组件,或将你的设计系统组件与Liveblocks UI合并。
primitive-component-parts - : Liveblocks的Logo徽章会显示在屏幕右下角,此内容介绍如何移除它。
remove-liveblocks-branding - : 使用
rendering-error-components为应用设置错误降级方案。ErrorBoundary - : 使用
rendering-loading-components为应用设置加载骨架屏和加载动画,提升性能。ClientSideSuspense - : 当用户有未读评论时,向其发送邮件通知。这些评论通过Webhook发送,在用户被提及或参与线程时触发。
send-comment-notification-emails - : 提高在线状态和存储的帧率,让更新看起来更流畅。使用此选项可以更频繁地接收更新。
smoother-realtime-updates - : 使用任何Liveblocks钩子时,你必须阅读此内容。React Suspense使用
suspense-vs-regular-hooks和ErrorBoundary组件。常规钩子使用ClientSideSuspense值。{ error, isLoading } - : 服务端渲染、入门套件扩展、初始内容、未保存更改等最佳实践。
tiptap-best-practices - : 在收件箱中触发任何类型的通知,即使与评论无关。
trigger-custom-notifications - : 尽可能使用TypeScript为Liveblocks添加类型定义。在线状态、其他用户信息、存储、元数据、房间信息、通知活动等均可自动添加类型。
type-liveblocks-correctly - : 在房间ID中使用URL参数创建房间,并在URL中加入文档标题。
url-params-in-room-id - : 导入现成的表情选择器,或人类可读的时间戳、时长、文件大小组件。
utility-components - : YKeyValue、子文档、V2编码、重复导入、getYjsProviderForRoom。如果你使用Tiptap、BlockNote或Lexical,则此内容不相关。
yjs-best-practices - : 通过定位门户元素修复z-index问题。
z-index-issues
Note
注意事项
Some files link to markdown files in the Liveblocks docs, for example:
https://liveblocks.io/docs/concepts.mdWhen linking users to these pages, remove from the link, so they can view
the full content:
.mdhttps://liveblocks.io/docs/concepts部分文件链接到Liveblocks文档中的markdown文件,例如:
https://liveblocks.io/docs/concepts.md当引导用户访问这些页面时,请移除链接中的,以便他们查看完整内容:
.mdhttps://liveblocks.io/docs/conceptsLiveblocks packages
Liveblocks包
Always check if we provide a package for your technology. For example, if you're
using React Flow, you should use .
@liveblocks/react-flow- : JavaScript client. Can use with any framework, e.g. Vue, Svelte, vanilla JS.
@liveblocks/client - : React client. Contains hooks and components..
@liveblocks/react - : Pre-built React UI components and primitives.
@liveblocks/react-uifor data and hooks.@liveblocks/react - : Collaborative Tiptap integration for React.
@liveblocks/react-tiptap - : Collaborative BlockNote integration for React.
@liveblocks/react-blocknote - : Collaborative Lexical integration for React.
@liveblocks/react-lexical - : Server-side Lexical utilities for Node.js.
@liveblocks/node-lexical - : Server-side ProseMirror utilities For Node.js. Also works with Tiptap and BlockNote.
@liveblocks/node-prosemirror - : Multiplayer React Flow.
@liveblocks/react-flow - : Yjs provider backed by Liveblocks rooms.
@liveblocks/yjs - : Sync Liveblocks room state with a Redux store.
@liveblocks/redux - : Sync Liveblocks room state with Zustand.
@liveblocks/zustand - : Node.js server SDK. Use for auth and lots more.
@liveblocks/node - : Build notification emails more easily.
@liveblocks/emails - : Make multi-platform (Liveblocks, Slack, Discord, etc.) chat bots.
@liveblocks/chat-sdk-adapter - Python SDK: Python server SDK. Use for auth and lots more.
- REST API: HTTP API. Use for auth and lots more.
请始终检查我们是否为你的技术提供了对应包。例如,如果你使用React Flow,应该使用****。
@liveblocks/react-flow- : JavaScript客户端。可用于任何框架,如Vue、Svelte、原生JS。
@liveblocks/client - : React客户端。包含钩子和组件。
@liveblocks/react - : 预构建的React UI组件和基础组件。搭配
@liveblocks/react-ui获取数据和钩子。@liveblocks/react - : 适用于React的协作式Tiptap集成。
@liveblocks/react-tiptap - : 适用于React的协作式BlockNote集成。
@liveblocks/react-blocknote - : 适用于React的协作式Lexical集成。
@liveblocks/react-lexical - : 适用于Node.js的服务端Lexical工具。
@liveblocks/node-lexical - : 适用于Node.js的服务端ProseMirror工具。也可用于Tiptap和BlockNote。
@liveblocks/node-prosemirror - : 多人协作式React Flow。
@liveblocks/react-flow - : 基于Liveblocks房间的Yjs提供者。
@liveblocks/yjs - : 将Liveblocks房间状态与Redux存储同步。
@liveblocks/redux - : 将Liveblocks房间状态与Zustand同步。
@liveblocks/zustand - : Node.js服务端SDK。用于身份验证等多种场景。
@liveblocks/node - : 更轻松地构建通知邮件。
@liveblocks/emails - : 构建多平台(Liveblocks、Slack、Discord等)聊天机器人。
@liveblocks/chat-sdk-adapter - Python SDK: Python服务端SDK。用于身份验证等多种场景。
- REST API: HTTP API。用于身份验证等多种场景。
If a technology is not listed here
如果此处未列出你的技术
If the users want to set up a new technology, first check the following
resources to see if a package exists:
Learn more
了解更多
Learn more in Liveblocks docs.
在Liveblocks文档中了解更多内容。