Closed
Description
Description
The issue arises when multiple client connections come in for the same document, the first connection will kick off and await the onLoadDocument
hook, however subsequent connections (while its still loading) incorrectly receive a connection to an empty document. When paired with @hocuspocus/provider
it changes the meaning on onConnect
and onSync
. For the first client both of those hooks imply that the document has been loaded. For the second connection it is ambiguous if the document has been loaded.
Steps to reproduce the bug
- client1 connects to doc
- client1 connection invokes
createDocument
this.documents.set(documentName, document)
immediately happens- client1 starts
onLoadDocument
async hook - client2 connects, sees that
this.documents.has(documentName)
is true and receives an empty doc, and successfully connects to an empty doc - client1
onLoadDocument
hook resolves - client1 successfully connects
Expected behavior
- client1 connects to doc
- client1 connection invokes createDocument
- client1 starts
onLoadDocument
async hook - client2 connects, sees that
onLoadDocument
is still in progress - client1
onLoadDocument
hook resolves - client1 successfully connects
- client2 successfully connects