automerge / automerge-classic

A JSON-like data structure (a CRDT) that can be modified concurrently by different users, and merged again automatically.
http://automerge.org/
MIT License
14.76k stars 467 forks source link

If the first change is empty, it is not encoded properly. #456

Closed ghost closed 2 years ago

ghost commented 2 years ago

Hi there. The following code crashes on the third change with:

let d = Automerge.init();
d = Automerge.emptyChange(d);
d = Automerge.change(d, (doc) => (doc.z = 1));
d = Automerge.change(d, (doc) => (doc.z = 1000));

The full trace is:

encoding.js:153 Uncaught RangeError: value is not an integer
    at DeltaEncoder.appendInt53 (encoding.js:153)
    at DeltaEncoder.appendRawValue (encoding.js:764)
    at DeltaEncoder.flush (encoding.js:751)
    at DeltaEncoder._appendValue (encoding.js:627)
    at DeltaEncoder.appendValue (encoding.js:573)
    at DeltaEncoder.appendValue (encoding.js:945)
    at appendOperation (new.js:636)
    at appendChange (new.js:1676)
    at BackendDoc.applyChanges (new.js:1841)
    at Object.applyLocalChange (backend.js:84)

I can tell from my debugging:

I hope these breadcrumbs are helpful.

ept commented 2 years ago

Thanks @jrakow for the helpful bug report! I have fixed the issue in #457. Could you give it a try please?

ghost commented 2 years ago

Thanks for the quick fix. It works now.

ghost commented 2 years ago

(Should not have closed this issue, while the PR is still open.)