share / share/sharedb

Created doc and changed on submit not synced in sorted collection

Open
#130 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
6.5k
Forks
456
Avg merge
1d 5h
Merged PRs (30d)
5

Description

I was updating my derby app to the latest version so it could be compatible with node 6.x and came across the same problem I reported earlier #https://github.com/derbyjs/derby/issues/518 with sharejs.

TL;DR; if a document is created and changed serve side in the submit hook an after is added to a sorted query, the client that created the document does not receive the changes made by the submit hook.

This time around I was able to fix my issue by adding these lines to the _opAcknowledged method

Doc.prototype._opAcknowledged = function(message) {
  if (this.inflightOp.create) {
    this.version = message.v;
    +++ this._clearInflightOp();
    +++ return this.fetch();
  } else if (message.v !== this.version) {
    // We should already be at the same version, because the server should
    // have sent all the ops that have happened before acknowledging our op
    console.warn('Invalid version from server. Expected: ' + this.version + ' Received: ' + message.v, message);

    // Fetching should get us back to a working document state
    return this.fetch();
}

Although this works well for me it breaks tests, I'm sure there is a better way to change a document at creation time that does not have this problems.

So if anyone has some insight to this please comment, thanks.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the _opAcknowledged method in lib/client/doc.js and compare the reported change with the existing tests. Reproduce creation and server-side submit-hook changes in a sorted query, then verify that the creating client receives those changes without breaking the test suite.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.