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(whiteboard): Prevent Parent Id Crash when Erasing Grouped Shapes #16423

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 14 additions & 2 deletions bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx
Expand Up @@ -190,7 +190,18 @@ export default function Whiteboard(props) {
persistShape(shape, whiteboardId);
}
});
removeShapes(deletedShapes, whiteboardId);

//order the ids of shapes being deleted to prevent crash when removing a group shape before its children
const orderedDeletedShapes = [];
deletedShapes.forEach(eid => {
if (shapes[eid]?.type !== 'group') {
orderedDeletedShapes.unshift(eid);
} else {
orderedDeletedShapes.push(eid)
Comment on lines +197 to +200
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it has to be the reverse here, first delete the group shape, and then the children

Copy link
Member

Choose a reason for hiding this comment

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

deleting the group shape first leads to the "shape has a parent that does not exist" error

}
});

removeShapes(orderedDeletedShapes, whiteboardId);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, I noticed we are sending empty removeAnnotations messages to akka when the list is empty here (probably it was already like this before).
There is no side-effect, but it's better to add a check if it's not empty

}

React.useEffect(() => {
Expand All @@ -217,7 +228,7 @@ export default function Whiteboard(props) {
}
});

const removed = prevShapes && findRemoved(Object.keys(prevShapes),Object.keys((shapes)))
const removed = prevShapes && findRemoved(Object.keys(prevShapes),Object.keys((shapes)));
if (removed && removed.length > 0) {
tldrawAPI?.patchState(
{
Expand All @@ -236,6 +247,7 @@ export default function Whiteboard(props) {
},
);
}

next.pages[curPageId].shapes = shapes;
changed = true;
}
Expand Down