-
-
Notifications
You must be signed in to change notification settings - Fork 262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'sync' event is fired before document is loaded #81
Comments
Hi @Flamenco, The "synced" event is fired when the client received the initial state from the server. However, it seems that the server loads the content from leveldb after the client is already synced. This is most likely a bug in the y-leveldb integration. |
@dmonad OK I will look under the hood in the leveldb code. I'm closing this for now. |
y-websocket has this code: websocket.onopen = () => {
provider.wsLastMessageReceived = time.getUnixTime()
provider.wsconnecting = false
provider.wsconnected = true
provider.wsUnsuccessfulReconnects = 0
provider.emit('status', [{
status: 'connected'
}])
// always send sync step 1 when connected
const encoder = encoding.createEncoder()
encoding.writeVarUint(encoder, messageSync)
syncProtocol.writeSyncStep1(encoder, provider.doc)
websocket.send(encoding.toUint8Array(encoder))
// broadcast local awareness state
if (provider.awareness.getLocalState() !== null) {
const encoderAwarenessState = encoding.createEncoder()
encoding.writeVarUint(encoderAwarenessState, messageAwareness)
encoding.writeVarUint8Array(encoderAwarenessState, awarenessProtocol.encodeAwarenessUpdate(provider.awareness, [provider.doc.clientID]))
websocket.send(encoding.toUint8Array(encoderAwarenessState))
}
} So it appears as you mentioned, sync is sent before any documents are actually loaded from persistence. |
I met the same problem when yjs server load doc history data from MySQL Database. How to fix:
|
I ran into this issue as well. I believe it was because in the default implementation of the y-websocket server, sometimes the sync events are fired before the document is loaded from In particular, on this line: https://github.com/yjs/y-websocket/blob/master/bin/utils.js#L37 I fixed this by modifying |
- Source: yjs#81
Describe the bug
Sync is called with isSynced true, but my document item is empty. This behavior is intermittent.
I need to add a delay before accessing the document.
Here is a helper function that includes a delay that resolves the problem. Without the delay, my doc.getText().length is sometimes '0', even though a document exists in the backend.
My test show the bigger the document, the more delay i need to add.
For reference, my backend is the published server example using a leveldb store.
The text was updated successfully, but these errors were encountered: