Merging 2 docs with different histories (excluding Text/Array)

@erin Erin Masatsugu
Wed, 12 Nov 2025 01:11:36 +0000

If I don’t have any Array or Text fields in my doc, is it actually possible to merge 2 docs with different histories? Bc Maps use LWW based on timestamps regardless?

      const clientDoc = new Y.Doc()
      clientDoc.getMap('m').set('x', 1)
      clientDoc.getMap('m').set('x', 2)
      // {x: 2}

      const serverDoc = new Y.Doc()
      serverDoc.getMap('m').set('x', 2)
      // {x: 2}

      clientDoc.getMap('m').set('x', 3)
      // {x: 3}

      // This doesn't work -- results in {x: 2}
      // Y.applyUpdate(serverDoc, Y.encodeStateAsUpdate(clientDoc))

      // This seems to work -- results in {x: 3}
      const serverStateVector = Y.encodeStateVector(serverDoc)
      const diff = Y.encodeStateAsUpdate(clientDoc, serverStateVector)
      Y.applyUpdate(serverDoc, diff)