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

Crash when deleting a modified table row added in the same change #462

Closed ghost closed 2 years ago

ghost commented 2 years ago

Hi.

Thanks for the fixing the last bug I reported. Here is another one :smiley:

The following code crashes on Automerge 1.0.1-preview.6:

Automerge.change(Automerge.init(), (doc) => {
    doc.table = new Table();

    const id = doc.table.add({});
    const row = doc.table.byId(id);

    row.x = 3;

    doc.table.remove(id);
});

The exception is:

RangeError: Not a valid opId: a5001bd114cf4191b7b9945b108218fa
    at parseOpId (…/node_modules/automerge/src/common.js:25:11)
    at Array.map (<anonymous>)
    at …/node_modules/automerge/backend/columnar.js:144:38
    at Array.map (<anonymous>)
    at parseAllOpIds (…/node_modules/automerge/backend/columnar.js:139:29)
    at encodeChange (…/node_modules/automerge/backend/columnar.js:711:33)
    at Object.applyLocalChange (…/node_modules/automerge/backend/backend.js:83:24)
    at makeChange (…/node_modules/automerge/frontend/index.js:98:70)
    at Object.change (…/node_modules/automerge/frontend/index.js:252:12)
    at Object.change (…/node_modules/automerge/src/automerge.js:34:29)

I tried debugging it, but got lost in the proxy code.

ept commented 2 years ago

Thanks @jrakow for the bug report! I've fixed the issue.