joebobmiles / zustand-middleware-yjs

Zustand middleware that enables sharing of state between clients via Yjs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Uncaught TypeError: sharedType.toJSON is not a function

arvinxx opened this issue · comments

Describe the bug

I'm try to intergrate into our product, but I found a problem:

Uncaught TypeError: sharedType.toJSON is not a function
    at patchSharedType (yjs.mjs:293:1)
    at yjs.mjs:341:1
    at Array.forEach (<anonymous>)
    at patchSharedType (yjs.mjs:294:1)
    at yjs.mjs:344:1
    at Array.forEach (<anonymous>)
    at patchSharedType (yjs.mjs:294:1)
    at yjs.mjs:341:1
    at Array.forEach (<anonymous>)
    at patchSharedType (yjs.mjs:294:1)
    at yjs.mjs:341:1
    at Array.forEach (<anonymous>)
    at patchSharedType (yjs.mjs:294:1)
    at yjs.mjs:464:1
    at transact (yjs.mjs:3292:1)
    at Doc.transact (yjs.mjs:505:1)
    at yjs.mjs:463:1
image

here is my data snapshot:

image

Screenshots

Versions (please complete the following information):

  • Browser [e.g. chrome, safari] Chrome
  • Version [e.g. 22] 1.3.0

Additional context
Add any other context about the problem here.

I'm going to need a minimal reproduction to debug this. Can you set up a CodeSandbox or repo that reproduces this error? Or at least the full JSON of your data snapshot instead of a screencap?

I've got the same error. I made a CodeSandbox example.

Reproduction steps:

  1. Open devtools
  2. Click on test
  3. Click on test2. You should see the error in the console
    (You may have to open a second tab with the same page before step 2/3)
  4. If you repeat clicking on any of the text items you should see the error repeat

I initially thought it might be an issue with the immer Zustand extension. But I removed it from the code and still got the error.

Thanks Alex!

From debugging your example, the bug is obvious: I forgot to convert strings to YText objects before shoving them in Yjs...

I'll get that fixed as soon as I have the time!

Release 1.3.1 fixes this issue, so going to close for now. If something else is broken, don't hesitate to reopen it!