stefanw / channels-yroom

Django Channels WebSocket consumer and worker for synchronizing Yjs clients
https://channels-yroom.readthedocs.io/en/latest/
MIT License
15 stars 5 forks source link

For some reason the YDoc sometimes remains unsynchronized when loading the page #6

Closed linspw closed 1 year ago

linspw commented 1 year ago

Gravação de tela de 04-05-2023 20:14:14.webm

This happens on half the tries. It does not generate errors in the console. Maybe it could be a concurrency issue. I've looked at the snapshot data and it's correct.

My Workaround is force sync again (works with it) 🤔

    const ydoc = new Y.Doc()
    this.provider = new HocuspocusProvider({
      url: `ws://localhost:8000/workspace/v1/documents/${this.document.id}`,
      name: String(this.document.id),
      document: ydoc,
      onSynced(data) {
        console.log(data)
      },
    })
    this.provider.on('connect', () => {
      this.provider?.forceSync()
    })

    this.editor = new Editor({
      extensions: [
        StarterKit.configure({
          history: false,
        }),
        Collaboration.configure({
          document: ydoc,
          field: 'content',
        }),
        CollaborationCursor.configure({
          provider: this.provider,
          user: { name: this.getRandomName(), color: this.getRandomColor() },
        }),
      ],
    }

Thanks in advance for your attention, Stefan!

Your project is amazing!

stefanw commented 1 year ago

I looked into this and I'm currently suspecting that HocuspocusProvider cannot read multiple y-protocol messages in one message receive (it could and probably should though). I'm looking into a workaround, but it is a bit annoying as I apparently need to split one initial reply (ie sync step 2, sync step 1 and awareness update) into multiple sends which could be one send.

stefanw commented 1 year ago

I added a setting to disable message pipelining. And I also found and fixed some bug in regards to syncing.

One other pesky synchronization bug that would lose messages was because of a broken/outdated version of the Python redis package (see this issue). Upgrading to redis>=4.5.5 (released 8.5.2023) fixes this.

Latest version v0.0.5 fixes these issues.

Docker compose example project includes now a TipTap editor and the docs have a more detailed guide for Tiptap.