How to manually load the Yjs doc?

So about the initial load of yjs, is there any way to start the loading of document when we want?
I came across this yDoc.load() function but not sure if it is used for that purpose.

Also is there any way to know when the document has completed loading? yDoc.isLoaded can I use this?

While each provider is different (i.e. providers are not standardized), the load typically begins as soon as the provider is instantiated, e.g. new IndexeddbPersistence(docName, ydoc). So if you want to manually “load” a YDoc from a provider, just wait to instantiate the provider instance.

The load status (i.e. sync status) is also provider-specific, since different providers can load at different times. They typically have a synced event you can subscribe to:

const provider = new IndexeddbPersistence(docName, ydoc)

provider.on('synced', () => {
  console.log('content from IndexedDB is loaded')

Nice, will implement this. Thanks for the help!

1 Like