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

Extraneous updates where origin == null when using full reload #157

Open
1 of 2 tasks
TeemuKoivisto opened this issue Oct 2, 2023 · 0 comments
Open
1 of 2 tasks
Assignees
Labels
bug Something isn't working

Comments

@TeemuKoivisto
Copy link

TeemuKoivisto commented Oct 2, 2023

Checklist

Describe the bug
So recently I had to debug a rather complicated bug in my yjs server. What happens is, I am loading updates from DB but the list is only partial. Which maybe wouldn't be so bad except that the client keeps generating extraneous updates on full reload thus overwriting the document in the DB.

This is a rough rundown of what's happening:

  1. Client sends syncstep1 & awareness
  2. Server fetches the updates, when doc is loaded sends syncstep2 & awareness
  3. Client applies the update and sets itself synced
  4. this.doc.on('update', this._updateHandler) triggers but the update is skipped since origin is the provider
  5. However, at this point the Y.Doc generates three additional updates with origin == null which are sent to the server
  6. Server receives them and happily commits them to the DB
  7. Doc has been overwritten

What makes this bad even when I am fetching the complete list are the three additional updates which are inserted every time the doc is loaded. The line in question is here

if (origin !== this) {
for which I added a check in my own fork of y-websocket where I skip them if (origin !== this && origin) {. However, this has introduced another bug - inconsistent state between client and the server.

I am not necessarily sure if this is a problem with core "yjs" package but I hope this is addressed regardless. I think it is quite serious issue with rather hard to debug complications. Also, as a side-note, adding "type": "module" to the package.json would be nice since Vite really doesn't like importing y-websocket otherwise.

To Reproduce

  1. git clone https://github.com/TeemuKoivisto/yjs-demos
  2. cd demo-server && npm i && npm start
  3. cd prosemirror-versions && npm i && npm start
  4. Open http://localhost:5173 (or what vite tells you)
  5. Open browser console, sometimes the extraneous updates with origin == null don't appear but doing a full refresh (Shift+Cmd+R in macOS) should cause it

EDIT: it appears to happen more often with older "yjs" version (13.4.x) and now, as I updated both the client and server to latest 13.6.8, it happens every second or so regular refresh Cmd+R and every hard refresh Shift+Cmd+R

Expected behavior
When doc is loaded, the client should not generate any more updates than necessary

Environment Information

  • Chrome 117.0.5938.88, NodeJS v18.13.0
  • "yjs": "^13.6.8" "y-prosemirror": "^1.2.1", "y-websocket": "^1.5.0",

Tested with 2 year older versions and it seems to be happening with them as well. My server is using yrs so I am highly confident the bug is with the client-side code.

@TeemuKoivisto TeemuKoivisto added the bug Something isn't working label Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants