Open orangejava opened 1 year ago
I think we are facing same issue.
Awarness is not removed when destroy
is called. Awareness is removed only when the tab is closed
But I'm not sure this is a feature or a bug.
When the provider is destroyed, it doesn't destroy
the awareness instance. This is the intended behavior because other parts of your software may rely on the awareness instance.
If the awareness changes (e.g. moving of a cursor), is still propagated over y-websocket after calling provider.destroy()
, this would be a bug. But I don't think this is the case here.
If you do awarenes.on('update', () => { console.log('update') })
, you will receive updates forever, unless you destroy the awareness instance. It's not bound to the provider instance.
Special case: the awareness
instance is destroyed when the associated ydoc
is destroyed.
You can also call awareness.destroy()
manually, if that is something you want to do.
However, I don't want to destroy the awareness instance when provider.destroy
is called, because other providers may still use the awareness instance. Awareness instances can be shared between providers.
Just make sure that you don't use old awareness instances. Alternatively, you can supply awareness
as an option to the WebsocketProvider
, so the instance doesn't change when you recreate the provider. See https://github.com/yjs/y-websocket/?tab=readme-ov-file#api
In any case, I recommend that you do provider.disconnect
instead of provider.destroy
and recreating a provider.
Checklist
Describe the bug I use a rich text editor with collaborative editing named Textbus, it use yjs and y-websocket to complete collaborative function. I use this editor with y-websocket and deploy a y-websocket node server. Open the editor it will new WebsocketProvider. When more than two users edit together( A and B), it collaborate normally; when A user click v button, A user will disconnect the y-websocket and the editor will destroy, I call the provider.destroy() to disconnect the y-websocket at the same time, A user and B user disconnect the collaborative, but in the Browser console, I see the A and B still print the awareness info, the correct should B print A not. The provider.awareness is not destroy completely, it cause the two provider.awareness send the message to other user client when A user connect to the editor again. I call the provider.awareness.destroy() to close the awareness update, it should add this statement (provider.awareness.destroy()) in the provider.destroy() function or modify the awareness.off() function.
To Reproduce Steps to reproduce the behavior:
Expected behavior When user call the provider.destroy() the provider should be destroyed completely includes awareness.
Screenshots I'm sorry for this, due to the network limitation, I cannot provide the screenshots temporarily.
Environment Information
Additional context Add any other context about the problem here.
Huly®: YJS-569