Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta Adatta ai principianti
#424 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
backend

Direzione di ricerca

Inizia da _awarenessUpdateHandler in YProvider, l'handler dei cambiamenti di awareness che trasmette a ogni modifica, e dall'handler dei messaggi di awareness che applica gli aggiornamenti del server usando il provider come origin. Aggiungi un return anticipato quando l'origin è il provider, così un client non rinvia gli aggiornamenti ricevuti dal server. È fatto quando lo spostamento del cursore in una scheda invia un frame invece di N e i cursori remoti continuano a essere mostrati nelle altre schede. Un test che verifichi che l'handler salti gli aggiornamenti con origin del server lo dimostrerebbe.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
TypeScript
Stelle
1.3k
Fork
84
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di cloudflare/partykit

Tutte le issue di cloudflare/partykit

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.