Gojs-debug Uncaught Error: Rect.intersects:x must be a real number type, and not NaN or Infinity: NaN

Hello, the go-debug.mjs:8 Uncaught Error: Rect.intersects:x must be a real number type, and not NaN or Infinity: NaN error occurs when I perform the redo operation after removal of some tree nodes. The error is caused by a custom link. The link’s actualBounds.x is NaN. For the custom link template I use new go.Link() - the custom link is used for the TreeLayout.

Partial stack trace:

go-debug.mjs:8 Uncaught Error: Rect.intersects:x must be a real number type, and not NaN or Infinity: NaN
    at Util.n (go-debug.mjs:8:1997)
    at Util.r (go-debug.mjs:8:2408)
    at Rect.intersects (go-debug.mjs:10:36233)
    at Rect.intersectsRect (go-debug.mjs:10:36118)
    at Layer.Km (go-debug.mjs:14:5388)
    at Layer.Ji (go-debug.mjs:14:3819)
    at Diagram.yR (go-debug.mjs:15:27233)
    at Diagram.Ji (go-debug.mjs:15:26693)
    at Diagram.Sr (go-debug.mjs:15:24422)
    at Diagram.maybeUpdate (go-debug.mjs:15:22973)
n	@	go-debug.mjs:8
r	@	go-debug.mjs:8
intersects	@	go-debug.mjs:10
intersectsRect	@	go-debug.mjs:10
Km	@	go-debug.mjs:14
Ji	@	go-debug.mjs:14
yR	@	go-debug.mjs:15
Ji	@	go-debug.mjs:15
Sr	@	go-debug.mjs:15
maybeUpdate	@	go-debug.mjs:15
bR	@	go-debug.mjs:15
doModelChanged	@	go-debug.mjs:23
doModelChanged	@	go-debug.mjs:23
Diagram.nP	@	go-debug.mjs:14
Hw	@	go-debug.mjs:41
i	@	go-debug.mjs:13
undo

Have you got some piece of advice on how to debug it further or what I could have missed during my implementation that now causes this issue?

Which version of GoJS are you using?

What is your link template?

Can you show screenshots from before and after the operation that you undo and then redo?

GoJS version: 3.0.12
Link template: new go.Link()

I was able to fix it for my project by calling diagram.model.removeNodeData and diagram.model.removeLinkData instead of diagram.removeParts.

So the operation that you later undid and then redid was a transaction in which you called Diagram.removeParts?

That’s right.

Hmmm, I’m unable to reproduce the problem. Here’s what I just tried:

<!DOCTYPE html>
<html lang="en">
  <body>
    <script src="https://cdn.jsdelivr.net/npm/gojs/release/go-debug.js"></script>
    

    <div id="myDiagramDiv" style="width: 800px; height: 500px"></div>
    <button id="myTestButton">Delete selection via Model.remove...Data</button>
    <button id="myTestButton2">Delete selection via Diagram.removeParts</button>
    <button onclick="myDiagram.commandHandler.undo()">Undo</button>
    <button onclick="myDiagram.commandHandler.redo()">Redo</button>

    <script id="code">
function init() {
  myDiagram = new go.Diagram("myDiagramDiv", {
      "undoManager.isEnabled": true
    });

  myDiagram.nodeTemplate = new go.Node("Auto", {
      resizable: true,
      width: 400,
      height: 100,
      background: "lightblue",
    })
    .bindTwoWay("desiredSize", "size", go.Size.parse, go.Size.stringify)
    .bindTwoWay("location", "loc", go.Point.parse, go.Point.stringify)
    .add(
      new go.Shape({ fill: null, strokeWidth: 0 }),
      new go.Panel("Graduated", {
        graduatedMin: 0,
        graduatedMax: 100,
        graduatedTickUnit: 10,
        background: "lightgreen",
        alignment: new go.Spot(0, 0, -100, 0),
        alignmentFocus: go.Spot.TopLeft
      }).add(
        new go.Shape({ geometryString: "M0 0 H800" }),
        new go.Shape({ geometryString: "M0 0 V10" }),
        new go.TextBlock({ segmentOffset: new go.Point(0, 12) })
      )
    );

  myDiagram.linkTemplate =
    new go.Link({ routing: go.Routing.AvoidsNodes })
      .add(
        new go.Shape()
      );

  myDiagram.model = new go.GraphLinksModel(
    [
      { key: 1, text: "Alpha", loc: "0 0", color: "lightblue" },
      { key: 2, text: "Beta", loc: "0 150", color: "lightgreen" },
      { key: 3, text: "Gamma", loc: "0 300", color: "pink" }
    ],
    [
      { from: 1, to: 3 }
    ]
  );
}
window.addEventListener("DOMContentLoaded", init);

document.getElementById("myTestButton").addEventListener("click", e => {
  myDiagram.model.commit(m => {
    myDiagram.selection.each(part => {
      if (part instanceof go.Link) {
        m.removeLinkData(part.data);
      } else {
        m.removeNodeData(part.data);
      }
    })
  });
});

document.getElementById("myTestButton2").addEventListener("click", e => {
  myDiagram.commit(diag => {
    myDiagram.removeParts(myDiagram.selection);
  });
});
    </script>
  </body>
</html>

Thank you, maybe it is caused by some other code in the project. But still I managed to move forward with removeLinkData/removeNodeData. Thank you for your help!