Yjs: data seems to be lost when reopening the app

Hello! :smiley:

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

The problem

Any changes that are made seem to be lost when closing and opening the app again. It doesn’t matter how much time I leave the app open.

Making any changes with the app open, either from that instance or another, brings back the changes that were lost.

I don’t see any errors in the web browser console when running the app with webxdc-dev run dist or when opening the Developer Tools from Delta Chat Desktop.

How to reproduce the problem

I created a minimal WebXDC example app that reproduces the issue.

This is the repository of the minimal WebXDC example app: uuid-manager. Here you have the built app, ready to share with Delta Chat:
app.xdc (30.5 KB).

I’ve only seen it happen with Delta Chat Desktop (2.11.1) and when using webxdc-dev run dist - it happens almost every time. Delta Chat Android seems unafected: I can’t reproduce it there. (This is both for the example app and the actual app.)

To reproduce the problem:

  1. Open the app.
  2. Add some UUIDs.
  3. Delta Chat Desktop: close the app. webxdc-dev: press the stop (square) button.
  4. Delta Chat Desktop: open the app again. webxdc-dev: press the play (triangle) button.

The UUIDs that have been added are missing. In the web browser console there aren’t any errors. If you add another UUID now, then the previous ones and the new one appear. There are logs that show when UUIDs are processed.

Why is this happening? Am I incorrectly creating and using yjs collections? Am I misusing preact?

I updated some dependencies that had newer versions available:

  • preact: 10.27.2 → 10.28.0
  • yjs: 1.1.1 → 1.2.0

The issue still takes place. Here you have the updated, built app, ready to share with Delta Chat:
app.xdc (31.1 KB)

Looking at the logs, this is all that gets printed

App
Subscribed!
Observing!

I have stared at the code for a while (though using the debugger would be better), and I think the reference app is settings a bad example again. The state gets initialized here, on class instantiation:

But y.observe() only gets called inside of subscribe():

This means that there is a gap between class instantiation an the time when subscribe() is called, yjs events can occur and thus can get lost. I am not sure if this is what causes the bug, but I think that needs to be addressed.
A possible solution is to update this.#immutableSnapshot immediately after uuidsArray.observe(). Although it looks like it’s time to rethink the approach that YStore takes.

1 Like