Yjs: it feels like the shared state has diverged?

Hello! :smiley:

I’m facing an issue with a WebXDC app that uses preact and Yjs.

The problem

When running instances of the app with webxdc-dev, everything works beautifully: data gets synced rapidly and reliably.

But when running instances of the app within Delta Chat, everything falls apart: data doesn’t get synced and the instances of each user seem to go on their own.

And when closing and opening the app again, sometimes data is apparently lost, but adding something makes everything that had been seen in that instance to appear again.

I suspect it has to do with me misusing preact and/or Yjs, but I can’t see what it is.

How to reproduce the problem

This is my problematic app: Divvy Bill (yjs-collections branch). Here you have the built app, ready to share with Delta Chat: app.xdc (39.4 KB)

The problem can manifest itself by following these steps, regardless of the time you wait between them:

  1. User A: send the app to User B.
  2. User A: open the app.
  3. User A: join the bill.
  4. User A: add an expense.
  5. User A: leave the app open.
  6. User B: open the app.
  7. User B: join the bill.
  8. User B: leave the app open.

After following these steps, I’ve never seen User A and User B have the same data. Data doesn’t get synced even when leaving both instances open for a while: each expense remains solely in the instance that created it.

Why does this happen?

Following these steps using webxdc-dev works as expected.

It seems to be a “me” problem

Divvy Bill is a fork of this other app: Split Bill, which does things a bit different but works perfectly fine both with webxdc-dev and within Delta Chat.

Have you opened developer tools? I don’t think these errors are expected:

You seem to be passing the Yjs document as the document to webxdc.sendUpdate. It’s supposed to be a string: sendUpdate - Webxdc.

I believe you need to change this line.

-const document = titleText || "New project";
+const document = titleText.toString() || "New project";

Thank you, @WofWca, for helping me again! Indeed, that fixes the issue: when using Delta Chat, instances of the app can now properly sync their data!

But I’ve never seen these errors in the developer tool’s console. I tried both Firefox and Chromium. The only error I see before applying your fix is in Firefox: it complains that it cannot get the favicon.ico.

Do you see them when running the app with webxdc-dev? Or when running it within Delta Chat? I don’t know how to access the developer tools from there.

I also don’t understand why the same code worked with webxdc-dev. Do you know why?

Thank you!!! :smiley:

1 Like

Yes, Delta Chat Desktop. There is an advanced setting for that.

I don’t know, maybe it somehow manages to serialize the object, or maybe there is some fallback in case it fails.

You’re welcome!

1 Like