ueberdosis / hocuspocus

The CRDT Yjs WebSocket backend for conflict-free real-time collaboration in your app.
https://tiptap.dev/docs/hocuspocus/introduction
MIT License
1.35k stars 129 forks source link

HocusPocusProvider V2 initiates 2 connections despite setting the connect flag to false #594

Open ghost opened 1 year ago

ghost commented 1 year ago

Description The HocusPocusProvider initiates 2 connections to our YJS backend despite setting the connect flag (from v1) to true. It should set up 1 connection.

Steps to reproduce the bug Steps to reproduce the behavior:

  1. Go to the examples in the repository https://github.com/BitPhinix/slate-yjs .
  2. Upgrade the hocuspocus version on both the client and the server.
  3. Open the client in a browser. And open the Network tab.
  4. You would see 2 connections established to the hocuspocus backend.

Expected behavior A single connection should be formed between the client and the server.

Screenshot, video, or GIF

Screenshot 2023-04-29 at 11 56 52 PM

Environment?

Additional context The problem seems to be in this line where the connect parameter is not passed to the configuration.: https://github.com/ueberdosis/hocuspocus/blob/ed6441c1d82e614aea388dfb84617c691d18d524/packages/provider/src/HocuspocusProvider.ts#L220

janthurau commented 1 year ago

@osamatanveer I've just added an example to the provider documentation. If you want to use multiplexing, you'll have to create the websocket separately from the provider (see https://tiptap.dev/hocuspocus/provider/examples#multiplexing).

ghost commented 1 year ago

Thanks @janthurau. We're not trying to use multiplexing. It is just that when we connect using editor.connect() we see 2 web socket connection opened in the network tab. We still are facing this issue.

aonnikov commented 1 year ago

The same issue for me, as a dirty workaround I disconnect the configured websocket provider in addition to the Hocuspocus provider:

        provider.configuration.websocketProvider.disconnect()
        provider.disconnect()

Looks dirty, but works fine to me.

wangfupeng1988 commented 4 months ago

The same issue for me, as a dirty workaround I disconnect the configured websocket provider in addition to the Hocuspocus provider:

        provider.configuration.websocketProvider.disconnect()
        provider.disconnect()

Looks dirty, but works fine to me.

It looks like works fine to me too , thx