Preserving connections with custom rule while collapsing participants

Hello,

I have a custom rule that prevents reconnecting arrows to other objects that differ from the original object.

ruleProvider.addRule('connection.reconnect', 1100, context => {
  if(context.connection.target.id != context.target.id || context.connection.source.id != context.source.id){
    return false;
  }
});

Now when I collapse and expand the participants with replaceElement as the PopupMenu does, the participant gets replaced and so does its ID. replaceElement then tries to redraw the connections that were either on the children of the participant or on the participant itself. Because of the participant having a different ID the custom rule forbids to reconnect the connection.

You can see the described behaviour in this codesandbox.

Do you know a way to get around this behaviour? Having attributes on the businessObject does not work because it is deleted, too. If the only way is to replaceElement, how would that look like?

Thank you!