Copilot commented on code in PR #4045:
URL: 
https://github.com/apache/incubator-kie-tools/pull/4045#discussion_r4261900634


##########
packages/bpmn-editor/src/mutations/renameGlobalProperties.ts:
##########
@@ -39,4 +39,12 @@ export function updateProcessId({
       participant["@_processRef"] = newId;
     }
   }
+
+  // Keep the DI layer in sync, otherwise BPMNPlane.bpmnElement becomes a 
dangling IDREF.
+  definitions["bpmndi:BPMNDiagram"]?.forEach((diagram) => {
+    const plane = diagram["bpmndi:BPMNPlane"];
+    if (plane["@_bpmnElement"] === oldProcessId) {
+      plane["@_bpmnElement"] = newId;
+    }

Review Comment:
   plane` is used without a null/undefined guard, so `plane["@_bpmnElement"]` 
will throw if a `bpmndi:BPMNDiagram` entry is missing `bpmndi:BPMNPlane` (or if 
parsing ever yields it as undefined). Add a guard (or early return/continue) 
before dereferencing `plane`, and also consider that `bpmndi:BPMNPlane` can be 
serialized as an array in some XML-to-JSON conversions—update all planes when 
it’s an array.



##########
packages/bpmn-editor/src/mutations/renameGlobalProperties.ts:
##########
@@ -39,4 +39,12 @@ export function updateProcessId({
       participant["@_processRef"] = newId;
     }
   }
+
+  // Keep the DI layer in sync, otherwise BPMNPlane.bpmnElement becomes a 
dangling IDREF.
+  definitions["bpmndi:BPMNDiagram"]?.forEach((diagram) => {

Review Comment:
   definitions["bpmndi:BPMNDiagram"]` is iterated assuming it’s always an 
array. In BPMN files, `BPMNDiagram` can be singular, and depending on the XML 
parser configuration it may deserialize as an object rather than an array. To 
make this mutation robust and easier to reuse for future DI updates, normalize 
`BPMNDiagram` to an array (e.g., wrap singletons) before iterating.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to