Skip to content
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

Syncing has unexpected type #40

Closed
eberberich opened this issue Aug 12, 2024 · 4 comments
Closed

Syncing has unexpected type #40

eberberich opened this issue Aug 12, 2024 · 4 comments
Assignees
Labels

Comments

@eberberich
Copy link

Describe the bug

Unexpected Type

A clear and concise description of what the bug is.

To Reproduce

While pushing an object into a Y.Array, there is a Unexpected case error in the console

This is the stack

create3 @ error.js:12
unexpectedCase @ error.js:29
findRootTypeKey @ ID.js:89
write @ Item.js:675
writeStructs @ encoding.js:67
(anonymous) @ encoding.js:100
writeClientsStructs @ encoding.js:99
writeStateAsUpdate @ encoding.js:505
encodeStateAsUpdateV2 @ encoding.js:524
encodeStateAsUpdate @ encoding.js:555
(anonymous) @ y-indexeddb.js:40
Promise.then
storeState @ y-indexeddb.js:38
(anonymous) @ y-indexeddb.js:117
setTimeout
IndexeddbPersistence._storeUpdate @ y-indexeddb.js:116
(anonymous) @ observable.js:82
emit @ observable.js:82
cleanupTransactions @ Transaction.js:364
transact @ Transaction.js:440
push @ YArray.js:157

Followed by an abortion of the syncing
Expected behavior

No error and proper syncing

Environment Information

  • Chrome, Firefox
  • yjs "13.6.18"
  • y-indexeddb "9.0.12",

[x] This issue is a blocker for my project.

@eberberich
Copy link
Author

Removing this line, removes the error, but also the persistency

const ydocIndexeddbProvider = new IndexeddbPersistence(docName, ydoc);

@dmonad
Copy link
Member

dmonad commented Aug 12, 2024

Unable to reproduce

@dmonad dmonad closed this as not planned Won't fix, can't repro, duplicate, stale Aug 12, 2024
@eberberich
Copy link
Author

eberberich commented Aug 12, 2024

It is this function that throws

export const findRootTypeKey = type => {
  // @ts-ignore _y must be defined, otherwise unexpected case
  for (const [key, value] of type.doc.share.entries()) {
    if (value === type) {
      return key
    }
  }
  throw error.unexpectedCase()
}

Can you explain how the === may not be met? - in particular in light of using a Y.Array on JS (proxy [vue]) objects

The test contains some kind of recursion: value is a value of the map type.doc.share.entries(), which howeve is compared against type - but the mentioned map comes from a nested field of type

@eberberich
Copy link
Author

eberberich commented Aug 12, 2024

More info: It happens when the syncing from IndexedDB is still in progress and we already access somewhere else yDoc.getArray("events")

EDIT: If i wait with calling yDoc.getArray("events") until ydocIndexeddbProvider.on('synced') has been called, the error disappears! For example by using a promise and resolving it in the on-synced callback - and (only) then (i.e. upon then) calling the getArray

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants