Describe the bug
cellsAdded in CellsMixin.ts has two conditions that always evaluate to true, introduced in commit bc400a3:
// Line 673
if ((!extend || extend) && this.isExtendParentsOnAdd(cell) && this.isExtendParent(cell)) {
// Line 681
if (!constrain || constrain) {
The original code used extend == null || extend and constrain == null || constrain, which correctly defaulted to true when the parameter was omitted but honored an explicit false. The rewrite to !x || x is always true for any boolean value, making both parameters dead code.
This breaks groupCells, which passes constrain=false, extend=false at lines 96 and 100 of GroupingMixin.ts. For cells at negative coordinates, extendParent does not trigger, so constrainChild clamps children into the group's initial 0x0 area, destroying their width and position.
To Reproduce
Steps to reproduce the behavior:
const v1 = graph.insertVertex(parent, null, 'A', -200, -200, 80, 40);
const v2 = graph.insertVertex(parent, null, 'B', -100, -100, 80, 40);
graph.groupCells(null, 0, [v1, v2]);
// v1 and v2 now have width=0 and height=0
Expected behavior
groupCells should preserve child cell geometries. This likely worked correctly in mxGraph.
Screenshots
N/A
Environment
maxGraph version or commit: present on current main
- Desktop or mobile: Desktop
- OS and version: Linux
- Browser and version: Latest Chromium
Additional context
The fix is to replace the always-true conditions with simple boolean checks, matching how cellsMoved (line 1359 in the same file) already handles the same parameters correctly:
if (extend && this.isExtendParentsOnAdd(cell) && this.isExtendParent(cell)) {
this.extendParent(cell);
}
if (constrain) {
this.constrainChild(cell);
}
Describe the bug
cellsAddedin CellsMixin.ts has two conditions that always evaluate to true, introduced in commit bc400a3:The original code used
extend == null || extendandconstrain == null || constrain, which correctly defaulted to true when the parameter was omitted but honored an explicit false. The rewrite to!x || xis always true for any boolean value, making both parameters dead code.This breaks
groupCells, which passesconstrain=false, extend=falseat lines 96 and 100 of GroupingMixin.ts. For cells at negative coordinates,extendParentdoes not trigger, soconstrainChildclamps children into the group's initial 0x0 area, destroying their width and position.To Reproduce
Steps to reproduce the behavior:
Expected behavior
groupCellsshould preserve child cell geometries. This likely worked correctly inmxGraph.Screenshots
N/A
Environment
maxGraphversion or commit: present on current mainAdditional context
The fix is to replace the always-true conditions with simple boolean checks, matching how cellsMoved (line 1359 in the same file) already handles the same parameters correctly:
Hi and thanks for raising this problem.
Your analysis seems valid, we have seen a lot of regression introduced during the migration to TypeScript around null handling.
For the fix, we can use your proposal or explicitly use
constrain ?? true