Skip to content

'sync' event is fired before document is loaded #81

@Flamenco

Description

@Flamenco

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.

await waitForSync()
console.log(doc.getText().length)
async function waitForSync() {
    return new Promise((resolve, reject) => {
      if (wsProvider.synced) {
        setTimeout(() => {
          return resolve(undefined)
        }, 200)
      }
      wsProvider.once('sync', () => {
        setTimeout(() => {
          resolve(undefined)
        }, 200)
      })
    });
  }

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions