-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In conjunction with saving XML in commandStack.changed
, this module can lead to an infinite loop
#2
Comments
This was reported by Cawemo team as well (reported by Andreas Remdt). They actually need to use a workaround to get unblocked |
Some additional information: this issue only seems to appear when the last remaining element is deleted from the canvas. If you have any other elements (like tasks, events, etc.) left on the canvas, then it's working as intended. However, if you only have a StartEvent (or Pool) and delete it, the recursion happens. We also found an issue with the Undo/Redo logic: even with other elements being on the canvas, the deletion of a StartEvent can't be undone by pressing Ctrl+Z. It works for other elements though. Could this be related? |
Thanks for providing these additional details #2 (comment) 👏. We'll have a look and see if we can follow up on this one. |
After investigating this issue I've come to the conclusion that there's no easy solution. At the moment the best workaround is to unsubscribe before calling const handleChange = async () => {
modeler.off("commandStack.changed", handleChange);
const { xml } = await modeler.saveXML({ format: true });
modeler.on("commandStack.changed", handleChange);
console.log(xml);
};
modeler.importXML(xml);
modeler.on("commandStack.changed", handleChange); Try: https://codesandbox.io/s/bpmn-ioalign-to-origin-workaround-c56yy Alternatives:
Related issues found during the investigation: |
commandStack.changed
, this module can leads to an infinite loop.
commandStack.changed
, this module can leads to an infinite loop.commandStack.changed
, this module can lead to an infinite loop
To conclude my investigation: It is not safe to use I've sketched a safe way to export with By design, this module will perform alignment via a command. That has other consequences that make it unsuitable for auto-save: If you undid something, a new alignment command will be added, clearing your undo stack without you noticing. You may have that one on your radar already (https://github.com/camunda/cawemo/issues/6926). Long story short, do not use this module, at least not with automatic saving on Consider alternatives, i.e. the one sketched by @philippfromme or revise your auto-save strategy. A thought in that direction: Maybe alignment does not need to happen all the time but only once the user actually closes a diagram. |
Related to my investigation I added bpmn-io/diagram-js#535 for consideration. A module like auto-save would benefit from command stack compaction. As it is an invisible change for the user, it should be grouped with previous command stack actions and undone/re-done with them. |
Related to my investigation I found the following: Given the usage pattern documented above that leads to an infinite loop it can be interesting to see what align-to-origin sees. By design it does only align if necessary. That means even in recursive In practice however it continues to see that further alignment is needed. As it uses raw DOM APIs under the hood to measure the width and position of elements, it could be that we're not actually querying the correct sizes if alignment and querying happen in quick succession. I did also debug the effect of disabling visual compenstation. I found that one to not have any negative effect. Attaching a log that visualizes the issue: |
Describe the Bug
Users might not expect commands to be executed during export and listen to
commandStack.changed
to call#saveXML
which can lead to an unexpected infinite loop.Example: https://codesandbox.io/s/align-to-origin-bug-hmklo?file=/src/index.js
Steps to Reproduce
commandStack.changed
to call#saveXML
Expected Behavior
Either align to origin without the need for a command or somehow make it easier to avoid an unexpected infinite loop (e.g. by defaulting to
alignOnSave: false
.Environment
The text was updated successfully, but these errors were encountered: