Error: A Yjs Doc connected to room "#room-name" already exists
Closed this issue · 1 comments
jacobcoro commented
Describe the bug
I'm getting an error when reconnecting and calling new WebrtcProvider()
on a page refresh or after a disconnect.
To Reproduce
Steps to reproduce the behavior:
const provider = new WebrtcProvider(name, doc, {
password,
signaling: servers,
awareness,
});
Then call provider.disconnect()
or provider.destroy()
, or just try connecting again with the same code and params as above.
- Get error:
Error: A Yjs Doc connected to room "#room-name" already exists
Expected behavior
A new provider can be created and sync to the existing room without error. Should return the provider.
Environment Information
- Happens both in Browser [Chrome] and Node [Vitest]
- "y-webrtc": "^10.2.5"
- "yjs": "^13.5.16"
// src/y-webrtc.js
const openRoom = (doc, provider, name, key) => {
// there must only be one room
if (rooms.has(name)) {
throw error.create(`A Yjs Doc connected to room "${name}" already exists!`)
}
const room = new Room(doc, provider, name, key)
rooms.set(name, /** @type {Room} */ (room))
return room
}
jacobcoro commented
Sorry. I realized I new WebRtcrRovider
was getting called twice elsewhere in the code!