#786·yjs

Deleting non-empty Y.Map child from Y.Map triggers YMapEvent with **empty Y.Map** as `oldValue`.

Author: WebCoder49Created Jul 9, 2026Updated Jul 11, 2026
Labelsbug

Please save me some time and use the following template. In 90% of all issues I can't reproduce the problem because I don't know what exactly you are doing, in which environment, or which y-* version is responsible. Just use the following template even if you think the problem is obvious.

Checklist

Describe the bug The YMapEvent.oldValue is an empty YMap when deleting a non-empty YMap child from a YMap parent it is nested in.

To Reproduce Steps to reproduce the behavior:

  1. Install YJS version 13.6.31
  2. Write this file test.mjs:
javascript
import * as Y from "yjs";

const ydoc = new Y.Doc()
const ymap = ydoc.getMap("map");

ymap.observe(ymapEvent => {
  // sample code.
  ymapEvent.changes.keys.forEach((change, key) => {
    if (change.action === 'add') {
      console.log(`ymap: Property "${key}" was added. Initial value: `, ymap.get(key).toJSON())
    } else if (change.action === 'update') {
      console.log(`ymap: Property "${key}" was updated. New value: "${ymap.get(key)}". Previous value: `,change.oldValue)
    } else if (change.action === 'delete') {
      console.log(`ymap: Property "${key}" was deleted. New value: undefined. Previous value: `,change.oldValue.toJSON())
    }
  })
})

const ymap2 = new Y.Map();

ymap2.observe(ymapEvent => {
  // sample code.
  ymapEvent.changes.keys.forEach((change, key) => {
    if (change.action === 'add') {
      console.log(`ymap2: Property "${key}" was added. Initial value: `, ymap.get(key).toJSON())
    } else if (change.action === 'update') {
      console.log(`ymap2: Property "${key}" was updated. New value: "${ymap.get(key)}". Previous value: `,change.oldValue)
    } else if (change.action === 'delete') {
      console.log(`ymap2: Property "${key}" was deleted. New value: undefined. Previous value: `,change.oldValue.toJSON())
    }
  })
})

ymap2.set('hello', 'world')

ymap.set('key', ymap2)
ymap.delete('key')
  1. Run node test.mjs (but this bug also occurs on the web browser, with y-websocket and y-indexeddb attached)
  2. See this in the console:
javascript
ymap: Property "key" was added. Initial value:  { hello: 'world' }
ymap: Property "key" was deleted. New value: undefined. Previous value:  {}

(incorrect, since if "hello" were deleted from YMap first that would have appeared as a log.)

Expected behavior

javascript
ymap: Property "key" was added. Initial value:  { hello: 'world' }
ymap: Property "key" was deleted. New value: undefined. Previous value:  { hello: 'world' }

Screenshots Not applicable.

Environment Information

  • Browser / Node.js Node.js OR Chromium OR Firefox
  • Yjs version: 13.6.31

Additional context I'm away this evening, but I'd be willing to look into fixing this bug tomorrow (Friday).

  • I'm a sponsor
  • This issue is a blocker for my project.