diff --git a/package-lock.json b/package-lock.json index a17cd5cf..1412ec82 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "yjs", - "version": "13.4.0", + "version": "13.4.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 794de5e6..573ef12c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yjs", - "version": "13.4.0", + "version": "13.4.1", "description": "Shared Editing Library", "main": "./dist/yjs.cjs", "module": "./dist/yjs.mjs", diff --git a/src/utils/PermanentUserData.js b/src/utils/PermanentUserData.js index 0bbb2ee1..29fd1f52 100644 --- a/src/utils/PermanentUserData.js +++ b/src/utils/PermanentUserData.js @@ -51,7 +51,7 @@ export class PermanentUserData { }) }) }) - this.dss.set(userDescription, mergeDeleteSets(ds.map(encodedDs => readDeleteSet(new DSDecoderV1(encodedDs))))) + this.dss.set(userDescription, mergeDeleteSets(ds.map(encodedDs => readDeleteSet(new DSDecoderV1(decoding.createDecoder(encodedDs)))))) ids.observe(/** @param {YArrayEvent} event */ event => event.changes.added.forEach(item => item.content.getContent().forEach(addClientId)) ) diff --git a/tests/encoding.tests.js b/tests/encoding.tests.js index 97f69245..65563e9d 100644 --- a/tests/encoding.tests.js +++ b/tests/encoding.tests.js @@ -1,4 +1,5 @@ import * as t from 'lib0/testing.js' +import * as promise from 'lib0/promise.js' import { contentRefs, @@ -10,7 +11,11 @@ import { readContentType, readContentFormat, readContentAny, - readContentDoc + readContentDoc, + Doc, + PermanentUserData, + encodeStateAsUpdate, + applyUpdate } from '../src/internals.js' /** @@ -28,3 +33,31 @@ export const testStructReferences = tc => { t.assert(contentRefs[8] === readContentAny) t.assert(contentRefs[9] === readContentDoc) } + +/** + * There is some custom encoding/decoding happening in PermanentUserData. + * This is why it landed here. + * + * @param {t.TestCase} tc + */ +export const testPermanentUserData = async tc => { + const ydoc1 = new Doc() + const ydoc2 = new Doc() + const pd1 = new PermanentUserData(ydoc1) + const pd2 = new PermanentUserData(ydoc2) + pd1.setUserMapping(ydoc1, ydoc1.clientID, 'user a') + pd2.setUserMapping(ydoc2, ydoc2.clientID, 'user b') + ydoc1.getText().insert(0, 'xhi') + ydoc1.getText().delete(0, 1) + ydoc2.getText().insert(0, 'hxxi') + ydoc2.getText().delete(1, 2) + await promise.wait(10) + applyUpdate(ydoc2, encodeStateAsUpdate(ydoc1)) + applyUpdate(ydoc1, encodeStateAsUpdate(ydoc2)) + + // now sync a third doc with same name as doc1 and then create PermanentUserData + const ydoc3 = new Doc() + applyUpdate(ydoc3, encodeStateAsUpdate(ydoc1)) + const pd3 = new PermanentUserData(ydoc3) + pd3.setUserMapping(ydoc3, ydoc3.clientID, 'user a') +}