Skip to content
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

FIx undo/redo for collapsed subprocesses #957

Closed
wants to merge 2 commits into from

Conversation

jarekdanielak
Copy link
Contributor

Proposed Changes

Related to bpmn-io/bpmn-js#2269

Add some null checks to prevent crashes when undo/redo adds or removes a collapsed subprocess.

Checklist

To ensure you provided everything we need to look at your PR:

  • Brief textual description of the changes present
  • Visual demo attached
  • Steps to try out present, i.e. using the @bpmn-io/sr tool
  • Related issue linked via Closes {LINK_TO_ISSUE} or Related to {LINK_TO_ISSUE}

@jarekdanielak jarekdanielak requested review from nikku and barmac January 9, 2025 13:16
@jarekdanielak jarekdanielak self-assigned this Jan 9, 2025
@bpmn-io-tasks bpmn-io-tasks bot added the needs review Review pending label Jan 9, 2025
@barmac
Copy link
Member

barmac commented Jan 9, 2025

Do you have a branch with an integration test for bpmn-js? Let's verify that this PR fixes the issue when linked with bpmn-js.

Copy link
Member

@barmac barmac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests (in diagram-js too) which reproduce the issue and allow us to verify the fix.

@bpmn-io-tasks bpmn-io-tasks bot added in progress Currently worked on and removed needs review Review pending labels Jan 9, 2025
@jarekdanielak
Copy link
Contributor Author

I extended the integration tests in bpmn-js with one that covers this bug. Failing with current version, passes with the change: bpmn-io/bpmn-js@5d8240d

@jarekdanielak jarekdanielak requested a review from barmac January 9, 2025 14:51
@bpmn-io-tasks bpmn-io-tasks bot added needs review Review pending and removed in progress Currently worked on labels Jan 9, 2025
@@ -192,6 +192,11 @@ GraphicsFactory.prototype.updateContainments = function(elements) {
forEach(children.slice().reverse(), function(child) {
var childGfx = elementRegistry.getGraphics(child);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I struggle to understand in which situation this can become an issue, could you elaborate? And would you be able to model this as a test case in diagram-js?

From what I understand:

  • GraphicsFactory#updateContainment is being called after any change operation happened (ref)
  • At this stage, looking at the model, parents for updated children are collected
  • Then the children inside these parents are re-ordered
  • BUT some of the children are actually NOT part of the render tree anymore?

The BUT is the big issue for me. How can children exist, but not actually be rendered? Where don't we properly update the model before we render?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may also be that we messed up the bpmn-js implementation.

Copy link
Member

@nikku nikku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jarekdanielak Let's figure out if we fixed the root cause of the issue here, happy to help with a debug session / code review.

@bpmn-io-tasks bpmn-io-tasks bot added in progress Currently worked on and removed needs review Review pending labels Jan 10, 2025
@jarekdanielak
Copy link
Contributor Author

I spent some time debugging:

  • GraphicsFactory#updateContainment crashes because an element inside of a subprocess that is being deleted by undo still has a parent assigned (the subprocess).
  • Element's parent is correctly unset by Canvas#_removeElement, but is later brought back by MoveShapeHandler#revert.
  • MoveShapeHandler#revert is fired because elements.move is fired when creating a collapsed subprocess.

At this point I need some help. I don't know why we call elements.move when creating a new collapsed subprocess. It doesn't fire when creating other types of elements.

@nikku could you step in?

@barmac
Copy link
Member

barmac commented Jan 17, 2025

@jarekdanielak I'm happy to support you with this. We can have a debugging session together to root cause the problem.

@nikku
Copy link
Member

nikku commented Jan 17, 2025

Thanks @barmac, will remove this from my TODO list. If you folks cannot figure it out, please ping me again.

@jarekdanielak
Copy link
Contributor Author

jarekdanielak commented Jan 17, 2025

Debugging session conclusions so far:

image

After the shape was removed, it cannot be moved back to the previous parent which is not present on the canvas as well. Therefore, we established that the root cause of the problem is in the implementation of the collapsed subprocess. We still need to find a way to fix it.

@barmac
Copy link
Member

barmac commented Jan 17, 2025

The SubProcessPlaneBehavior is triggered on each shape.create. However, we could trigger this only once for elements.create command. This means that we would move the elements at the end of the action. We are trying this out.

@barmac
Copy link
Member

barmac commented Jan 17, 2025

There's more in this issue than we expected. @jarekdanielak will push our solution sketch with the still not working text annotation part. The diagram-js PR can be closed as we established that the root cause is in bpmn-js.

@jarekdanielak
Copy link
Contributor Author

Closing this one. More discussion and debugging will happen in bpmn-js: bpmn-io/bpmn-js#2275

@bpmn-io-tasks bpmn-io-tasks bot removed the in progress Currently worked on label Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants