Skip to content

fix(yjs): let the server decide who seeds an empty room - #3331

Merged
kulmann merged 2 commits into
mainfrom
fix/yjs-hydration-race-errors
Sep 11, 2026
Merged

fix(yjs): let the server decide who seeds an empty room#3331
kulmann merged 2 commits into
mainfrom
fix/yjs-hydration-race-errors

Conversation

@JammingBen

@JammingBen JammingBen commented Sep 8, 2026

Copy link
Copy Markdown
Member

Two clients opening the same file at once could both seed the Y.Doc, and the room then held the body twice. The awareness election that guarded this only waited a guessed 150ms.

Instead of solving this on the client side, the Yjs server now grants seeding to exactly one connection per room. It is the only party that sees every connection at once.

The grant is permission, not an instruction: the client still checks its own document first, so a grant for a room that already has content costs nothing. It passes to another writer when the holder leaves, and dies with the room.

fixes #3141

@JammingBen JammingBen self-assigned this Sep 8, 2026
@JammingBen
JammingBen force-pushed the fix/yjs-hydration-race-errors branch from f16fe78 to fb38a4a Compare September 8, 2026 09:40
@JammingBen
JammingBen marked this pull request as ready for review September 8, 2026 10:24
@JammingBen
JammingBen requested a review from kulmann September 8, 2026 10:24
Two clients opening the same file at once could both seed the Y.Doc, and
the room then held the body twice. The awareness election that guarded
this only waited a guessed 150ms, and a client has no signal that its
announce is visible to everyone.

The Yjs server now grants seeding to exactly one connection per room. It
is the only party that sees every connection at once, so no wait has to
be guessed.

The grant is permission, not an instruction: the client still checks its
own document first, so a grant for a room that already has content costs
nothing. It passes to another writer when the holder leaves, and dies
with the room.
@JammingBen
JammingBen force-pushed the fix/yjs-hydration-race-errors branch from 7b1b412 to d6a4e8e Compare September 10, 2026 11:44
@JammingBen
JammingBen added this pull request to stack #3346 September 10, 2026 11:51
@kulmann
kulmann merged commit b46a24e into main Sep 11, 2026
31 checks passed
@kulmann
kulmann deleted the fix/yjs-hydration-race-errors branch September 11, 2026 06:07
@openclouders openclouders mentioned this pull request Sep 11, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Y.Doc hydration can race

2 participants