diff --git a/cypress/component/helpers/yjs.cy.js b/cypress/component/helpers/yjs.cy.js index 6f4d261383f..7472e28adc8 100644 --- a/cypress/component/helpers/yjs.cy.js +++ b/cypress/component/helpers/yjs.cy.js @@ -70,7 +70,7 @@ describe('Yjs base64 wrapped with our helpers', function() { const stateA = getDocumentState(source) const update0A = getUpdateMessage(source, state0) const updateAA = getUpdateMessage(source, stateA) - expect(update0A.length).to.be.eq(40) + expect(update0A.length).to.be.eq(29) expect(updateAA).to.be.eq(undefined) }) diff --git a/src/helpers/yjs.js b/src/helpers/yjs.js index 6ed897eff76..f4fc64a17e5 100644 --- a/src/helpers/yjs.js +++ b/src/helpers/yjs.js @@ -51,7 +51,7 @@ export function applyDocumentState(ydoc, documentState, origin) { * * @param {Y.Doc} ydoc - encode state of this doc * @param {string} encodedBaseUpdate - base64 encoded doc update to build upon - * @return {string|undefined} + * @return {Uint8Array|undefined} */ export function getUpdateMessage(ydoc, encodedBaseUpdate) { const baseUpdate = decodeArrayBuffer(encodedBaseUpdate) @@ -65,8 +65,7 @@ export function getUpdateMessage(ydoc, encodedBaseUpdate) { encoding.writeVarUint(encoder, messageSync) const update = Y.encodeStateAsUpdate(ydoc, baseStateVector) syncProtocol.writeUpdate(encoder, update) - const buf = encoding.toUint8Array(encoder) - return encodeArrayBuffer(buf) + return encoding.toUint8Array(encoder) } /** @@ -74,12 +73,11 @@ export function getUpdateMessage(ydoc, encodedBaseUpdate) { * * Only used in tests right now. * @param {Y.Doc} ydoc - encode state of this doc - * @param {string} updateMessage - base64 encoded y-websocket sync message with update + * @param {Uint8Array} updateMessage - y-websocket sync message with update * @param {object} origin - initiator object e.g. WebsocketProvider */ export function applyUpdateMessage(ydoc, updateMessage, origin = 'origin') { - const updateBuffer = decodeArrayBuffer(updateMessage) - const decoder = decoding.createDecoder(updateBuffer) + const decoder = decoding.createDecoder(updateMessage) const messageType = decoding.readVarUint(decoder) if (messageType !== messageSync) { console.error('y.js update message with invalid type', messageType)