Undo / redo does not work with updateProperties

Hi everyone,

I ran into an issue with undo / redo in a custom properties panel with extension elements. I saw this thread which suggests to use commands. I also found this example which uses modeling.updateProperties to set the extension elements and has working undo / redo.

However, when I tried to use updateProperties to set the extension elements I noticed that undo / redo do not work, although the details are confusing. Unfortunately, I am not at liberty to share most of our code, so I will try to show the relevant parts and explain what is happening. Maybe someone has an idea.

Behaviour
Undo is generally working

  1. Create an element that has custom properties → element is created
  2. Press Ctrl+Z → element is removed

But with my custom properties things get weird

  1. Create an element that has custom properties → element is created
  2. Write a custom property → property is correctly set in the bpmn when downloaded
  3. Press Ctrl+Z → nothing happens, property is incorrectly still set in the bpmn when downloaded
  4. Press Ctrl+Z again → the element is removed

It seems to me as if the Write-Property-Action is correctly added to the command (event?) stack. It also is popped off the stack when undoing. But the actual writing is not undone.

Code (sort of)
As mentioned I cannot share much of our code, but this is the code I use to write the extension elements as well as the objects it uses.

Code

const modeling = useService('modeling');
console.log(JSON.stringify(element))
console.log(JSON.stringify(extensionElements))
return modeling.updateProperties(element, {extensionElements});

element

{
   "labels":[
      
   ],
   "children":[
      
   ],
   "id":"Activity_0s9re6u",
   "width":105,
   "height":55,
   "name":"test",
   "type":"bpmn:ServiceTask",
   "di":{
      "$type":"bpmndi:BPMNShape",
      "bounds":{
         "$type":"dc:Bounds",
         "x":588,
         "y":183,
         "width":105,
         "height":55
      },
      "id":"Activity_0s9re6u_di"
   },
   "x":588,
   "y":183,
   "order":{
      "level":5
   }
}

extensionElements

{
   "$type":"bpmn:ExtensionElements",
   "values":[
      {
         "$type":"activiti:Field",
         "name":"to",
         "string":{
            "$type":"activiti:String",
            "text":"asd"
         }
      },
      {
         "$type":"activiti:Field",
         "name":"from",
         "string":{
            "$type":"activiti:String",
            "text":"writingProperty"
         }
      },
      {
         "$type":"activiti:Field",
         "name":"subject",
         "string":{
            "$type":"activiti:String",
            "text":""
         }
      },
      {
         "$type":"activiti:Field",
         "name":"cc",
         "string":{
            "$type":"activiti:String",
            "text":""
         }
      },
      {
         "$type":"activiti:Field",
         "name":"bcc",
         "string":{
            "$type":"activiti:String",
            "text":""
         }
      },
      {
         "$type":"activiti:Field",
         "name":"html",
         "string":{
            "$type":"activiti:String",
            "text":""
         }
      },
      {
         "$type":"activiti:Field",
         "name":"attachmentName",
         "string":{
            "$type":"activiti:String",
            "text":""
         }
      },
      {
         "$type":"activiti:Field",
         "name":"attachmentMimeType",
         "string":{
            "$type":"activiti:String",
            "text":"text/plain"
         }
      },
      {
         "$type":"activiti:Field",
         "name":"attachmentContent",
         "string":{
            "$type":"activiti:String",
            "text":""
         }
      }
   ]
}

Generally you’ll be able to verify your logic without the properties panel in a focused unit test. I’d suggest you to do it, including undo + redo and verify that this works properly. If it does not, try to extract the scenario into something that we can inspect end-to-end, and then we’ll be able to help.

We use modeling#updateProperties at the core of the properties panel for Camunda extensions, not operating on activity but camunda extensions, of course. So I believe this is a userland bug.