yjs/y-webrtc

Error: A Yjs Doc connected to room "#room-name" already exists

Closed this issue · 1 comments

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.

  1. 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"

Screenshot 2023-05-06 at 18 16 48

Screenshot 2023-05-06 at 18 16 13

Screenshot 2023-05-06 at 18 15 51

Sorry not sure why sourcemaps aren't working, but I've found where it originates:
// 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
}

Sorry. I realized I new WebRtcrRovider was getting called twice elsewhere in the code!