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 id_prefix=oldShape.id.split('_')[0];
            ifActivityQuestionsPrefix.some(item=>item==id_prefix)){
              const goOn=confirm("Are you sure you want to proceed?,this will impact the security level!");
              if (!goOn){
                event.stopPropagation();
                event.preventDefault();

                var oldElement = elementRegistry.get(oldShape.id);
                var newElement = elementRegistry.get(newShape.id);

                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:

https://codesandbox.io/p/sandbox/replace-menu-provider-forked-lx9s5h?file=%2Fsrc%2Freplace%2FMyReplaceMenuProvider.js%3A28%2C15