This commit is contained in:
@@ -122,25 +122,33 @@ export class YjsDocument {
|
||||
bgConfigs?: BackgroundConfig[];
|
||||
}): void {
|
||||
this.doc.transact(() => {
|
||||
this.data.elements.clear();
|
||||
for (const el of state.elements) {
|
||||
this.data.elements.set(el.id, el);
|
||||
// Issue #7: Only clear and replace a map if the incoming array is non-empty.
|
||||
// Clearing maps when data is empty wipes CRDT data from other connected clients.
|
||||
if (state.elements.length > 0) {
|
||||
this.data.elements.clear();
|
||||
for (const el of state.elements) {
|
||||
this.data.elements.set(el.id, el);
|
||||
}
|
||||
}
|
||||
this.data.layers.clear();
|
||||
for (const layer of state.layers) {
|
||||
this.data.layers.set(layer.id, layer);
|
||||
if (state.layers.length > 0) {
|
||||
this.data.layers.clear();
|
||||
for (const layer of state.layers) {
|
||||
this.data.layers.set(layer.id, layer);
|
||||
}
|
||||
}
|
||||
this.data.blocks.clear();
|
||||
for (const block of state.blocks) {
|
||||
this.data.blocks.set(block.id, block);
|
||||
if (state.blocks.length > 0) {
|
||||
this.data.blocks.clear();
|
||||
for (const block of state.blocks) {
|
||||
this.data.blocks.set(block.id, block);
|
||||
}
|
||||
}
|
||||
if (state.groups) {
|
||||
if (state.groups && state.groups.length > 0) {
|
||||
this.data.groups.clear();
|
||||
for (const group of state.groups) {
|
||||
this.data.groups.set(group.id, group);
|
||||
}
|
||||
}
|
||||
if (state.bgConfigs) {
|
||||
if (state.bgConfigs && state.bgConfigs.length > 0) {
|
||||
this.data.bgConfig.clear();
|
||||
for (const cfg of state.bgConfigs) {
|
||||
// Use 'default' as the key since there is typically one background config
|
||||
|
||||
Reference in New Issue
Block a user