findNodeForKey when model is shared by two diagrams

Hi,

I’m having the problem that diagram.findNodeForKey() returns null, for a diagram that shares a model with another diagram, and for keys that appear to be in the model (as evidenced by printing the model to the console).

Here’s the creation of the second diagram. The word “layout” refers to a notion in the application, not to the GoJS notion of layout; it is a diagram.

let view   = document.getElementById(name);
let normal = go.Diagram.fromDiv(view);
let model  = normal.model; // N.B.: a GoJS Model object

layout =
    $(go.Diagram, swapDiv,
      {
          initialContentAlignment: go.Spot.Center,
          commandHandler: new DrawCommandHandler(),
          resizingTool: new ResizeMultipleTool(),
      PartResized : e => { layout.selection.each(part => { this.drawNode(part); }); },
          "undoManager.isEnabled": true
      });

layout.nodeTemplateMap = this.layoutNodeTemplates;
layout.linkTemplate = this.layoutLinkTemplate;
layout.model = model; // N.B.: the two diagrams share a Model object

// common listeners
this.addCommonDiagramListeners(layout);

// test
console.log(model.nodeDataArray);
let N = model.nodeDataArray.length;
for (let i = 0; i < N; ++ i)
{
let d = model.nodeDataArray[i];
let k = d.key;
let n = layout.findNodeForKey(k);
console.assert(n.data == d);
}

In the ‘test’ loop at the bottom, ‘n’ is null always. The console debugger shows for example k = -1, n = null.

The new diagram displays just fine, and otherwise behaves normally; it’s just that findNodeForKey doesn’t seem to work for it. This is the output of the console.log() call above.

(3) […]
0: Object { cat: "Dial$FOT12XtnOnT2dVeoT2dVeoOoiOT2jjT2jjT2jjT3jjjj", loc: "-296 -206", key: -1, … }
1: Object { cat: "Preset$FOT13XtnOnT2dVeoT2dVeoOosOT2jjT2jjT3jjjT3jjjT3jjjs", loc: "-97 -75", key: -2, … }
2: Object { cat: "EditNumBox$FOT14XtnOnT2dVeoT2dVeoOoiOT2jjT2jjT3jjjT3jjjddj", pos: "235.00000000000009 -167.00000000000009", key: -3, … }
length: 3

I found the problem: the ‘nodes’ in the second diagram are in fact bare parts, so “findPartForKey” is required to retrieve them.