From 7c3f6dcc8d045785b7975034acd95650eef2838f Mon Sep 17 00:00:00 2001 From: hjlarry Date: Fri, 10 Oct 2025 10:34:00 +0800 Subject: [PATCH] use cloneDeep instead of json.parse --- .../collaboration/core/collaboration-manager.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/web/app/components/workflow/collaboration/core/collaboration-manager.ts b/web/app/components/workflow/collaboration/core/collaboration-manager.ts index 41c1fdd811..39750d9d7d 100644 --- a/web/app/components/workflow/collaboration/core/collaboration-manager.ts +++ b/web/app/components/workflow/collaboration/core/collaboration-manager.ts @@ -1,5 +1,5 @@ import { LoroDoc, UndoManager } from 'loro-crdt' -import { isEqual } from 'lodash-es' +import { cloneDeep, isEqual } from 'lodash-es' import { webSocketClient } from './websocket-manager' import { CRDTProvider } from './crdt-provider' import { EventEmitter } from './event-emitter' @@ -582,7 +582,7 @@ export class CollaborationManager { } if (value !== null && typeof value === 'object') - target[prop as string] = JSON.parse(JSON.stringify(value)) + target[prop as string] = cloneDeep(value) else target[prop as string] = value }) @@ -609,7 +609,7 @@ export class CollaborationManager { // Clone data properties, excluding private ones Object.entries(newNode.data).forEach(([key, value]) => { if (shouldSyncDataKey(key) && value !== undefined) - nodeData.data[key] = JSON.parse(JSON.stringify(value)) + nodeData.data[key] = cloneDeep(value) }) this.nodesMap.set(newNode.id, nodeData) @@ -620,7 +620,7 @@ export class CollaborationManager { if (existingNode) { // Create a deep copy to modify - const updatedNode = JSON.parse(JSON.stringify(existingNode)) + const updatedNode = cloneDeep(existingNode) // Update position only if changed if (oldNode.position.x !== newNode.position.x || oldNode.position.y !== newNode.position.y) @@ -649,7 +649,7 @@ export class CollaborationManager { if (shouldSyncDataKey(key)) { const oldValue = (oldData as any)[key] if (!isEqual(oldValue, value)) - updatedNode.data[key] = JSON.parse(JSON.stringify(value)) + updatedNode.data[key] = cloneDeep(value) } }) @@ -680,7 +680,7 @@ export class CollaborationManager { Object.entries(newNode.data).forEach(([key, value]) => { if (shouldSyncDataKey(key) && value !== undefined) - nodeData.data[key] = JSON.parse(JSON.stringify(value)) + nodeData.data[key] = cloneDeep(value) }) this.nodesMap.set(newNode.id, nodeData) @@ -703,11 +703,11 @@ export class CollaborationManager { newEdges.forEach((newEdge) => { const oldEdge = oldEdgesMap.get(newEdge.id) if (!oldEdge) { - const clonedEdge = JSON.parse(JSON.stringify(newEdge)) + const clonedEdge = cloneDeep(newEdge) this.edgesMap.set(newEdge.id, clonedEdge) } else if (!isEqual(oldEdge, newEdge)) { - const clonedEdge = JSON.parse(JSON.stringify(newEdge)) + const clonedEdge = cloneDeep(newEdge) this.edgesMap.set(newEdge.id, clonedEdge) } })