YousefED / SyncedStore

SyncedStore CRDT is an easy-to-use library for building live, collaborative applications that sync automatically.
https://syncedstore.org
MIT License
1.69k stars 51 forks source link

"property not found on root doc then" when using promises #93

Closed vincesp closed 1 year ago

vincesp commented 1 year ago

Using syncedStore with a promise will yield a warning message when the promise is resolved.

Example code:

const storePromise = new Promise((resolve) => {
  ysocketio.on('document-loaded', (doc) => {
    if (doc.name === storeDef.name) {
      resolve(syncedStore(storeDef.shape, doc))
    }
  })
})

const store = await storePromise will yield the following message on the console:

property not found on root doc then
YousefED commented 1 year ago

Thanks for reporting. This warning is there to warn users that are using syncedstore wrongly, by querying for non-registered properties on the root doc. In your case, the way Promises are implemented, the browser probably queries for "then".

My assumption is nothing breaks in your app, right? In that case I'll mark the issue as closed, as at this moment, I don't think (unless many people run into this) we should hardcode an exception for the warning

vincesp commented 1 year ago

You are right, nothing breaks; and adding then: {} to the doc's shape suppresses the warning.

Yet, the warning is a bit confusing and only little useful. One could argue that it actually would be more useful to issue a warning if somebody ever tried to create a property then on the root doc – as that probably would cause some trouble down the line, not with syncedStore itself, but with another very common JavaScript pattern ("Thenable").