Block a replacement started by contextPad

Hi i need to control when an element type is changed. In particular i’m implementing some security path and i need to show an aler to the user if they try to edit it to make sure that they understand that this will impact the security. And if they click cancel and not go on, i need to block the replacement.
I tried to use this listener on this event but this does not block the replacement. I know i could undo it but in this path i have some zeebe element and this generate an error, so i need to clock the operation before its execution.
Here my code:
eventBus.on(“commandStack.shape.replace.preExecute”, function(event){
const context = event.context;
const oldShape = context.oldShape;
const newShape = context.newShape;

              const goOn=confirm("Are you sure you want to proceed?,this will impact the security level!");
              if (!goOn){

                var oldElement = elementRegistry.get(;
                var newElement = elementRegistry.get(;

                if (oldElement && newElement) {
                  modeling.replaceElement(oldElement, newElement);
                } else {
                  console.error('Failed to replace element: Element not found.');



Hi @Alessia_Volpi ,

instead of hooking into (synchronous) lifecycle events, it might be worth to modify the replace menu provider to not trigger a replace unless confirmed. You can achieve this with a custom replace provider, see the example codesandbox here: