Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[y-partyserver] Provider sends other clients' awareness back to the server

未关闭 适合新手
#424 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript
领域
backend

调研方向

从 YProvider 中的 _awarenessUpdateHandler 开始,它是每次变化都会广播的 awareness 变更处理函数;同时查看以 provider 作为 origin 应用服务端更新的 awareness 消息处理函数。当 origin 是 provider 时添加提前返回,使客户端不会重新发送从服务端收到的更新。完成标准是:一个标签页中移动光标时发送一帧而不是 N 帧,并且其他标签页中仍能渲染远程光标。一个检查处理函数会跳过服务端来源更新的测试可以证明这一点。

由索引模型根据 Issue 内容生成。

描述

What happens

YProvider's awareness handler sends a message on every awareness change, whatever its origin:

this._awarenessUpdateHandler = ({ added, updated, removed }, _origin) => { /* … */ broadcastMessage(/* … */) };

Awareness updates from the server are applied with the provider as origin (applyAwarenessUpdate(provider.awareness, …, provider) in the awareness message handler), so each client sends every other client's change straight back. YServer already relays every awareness message to all connections, so with N clients one cursor move costs the server N incoming frames instead of 1. On Durable Objects each of them is an invocation: a billed request, and a log event when Workers Logs is on.

Measured

y-partyserver 2.2.0 (the handler is the same on main), 3 Chromium tabs on one document, frames counted by wrapping WebSocket.prototype.send:

Now With the fix below
Cursor move (arrow key) in one tab 3 frames 1
Keystroke, with Tiptap's CollaborationCaret 10 4 (2 with ueberdosis/y-tiptap#55 fixed too)

Remote cursors still render in every tab with the fix.

Suggested fix
this._awarenessUpdateHandler = ({ added, updated, removed }, origin) => {
  if (origin === this) return; // from the server, which has already relayed it to everyone
  // …
};

Every client only needs to receive each awareness update once; re-sending is allowed but not needed (Yjs's author on the same y-websocket behaviour: https://discuss.yjs.dev/t/redundant-messages/1062). Happy to open a PR with a test.

主要语言
TypeScript
星标
1.3k
派生
84
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

cloudflare/partykit 的其他 Issue

查看 cloudflare/partykit 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。