loro-dev / loro

Reimagine state management with CRDTs. Make your app collaborative effortlessly.
https://loro.dev
MIT License
3.71k stars 70 forks source link

Empty objects are not returned #453

Closed raymonddaikon closed 1 week ago

raymonddaikon commented 1 week ago

When a Loro map value is an empty object, calling .toJSON() on the Loro map will omit the value. This is specifically a problem in loro-prosemirror where the attributes key is often an empty object. This is specifically a problem in nested containers as top level values will return an empty object, but for nested values inside Loro Lists etc. the value is completely omitted even though the data is being detected in the batch event diff. For example setting text as bold in prosemirror will trigger a change event on the map that will return diff: [{ attributes: bold: {}, retain: 1 }] but calling .toJSON() on that map will return attributes: {}. Update: Was reading the logs wrong, as it was changing the attributes value on the LoroText instead of the Map.