diff --git a/lib/network/modules/EdgesHandler.js b/lib/network/modules/EdgesHandler.js index e5935d20d..d2019df0d 100644 --- a/lib/network/modules/EdgesHandler.js +++ b/lib/network/modules/EdgesHandler.js @@ -461,8 +461,13 @@ class EdgesHandler { * @private */ _addMissingEdges() { - let edges = this.body.edges; let edgesData = this.body.data.edges; + if (edgesData === undefined || edgesData === null) { + // No edges DataSet yet; can happen on processing options + return; + } + + let edges = this.body.edges; let addIds = []; edgesData.forEach((edgeData, edgeId) => { diff --git a/test/Network.test.js b/test/Network.test.js index afec12c86..fea29b552 100644 --- a/test/Network.test.js +++ b/test/Network.test.js @@ -369,6 +369,27 @@ describe('Network', function () { }); + it('does not crash when dataChanged is triggered when setting options on first initialization ', function() { + // The init should succeed without an error thrown. + var options = { + nodes: { + physics: false // any value here triggered the error + } + }; + createSampleNetwork(options); + + // Do the other values as well that can cause this./ + // 'any values' applies here as well, expecting no throw + options = {edges: {physics: false}}; + createSampleNetwork(options); + + options = {nodes: {hidden: false}}; + createSampleNetwork(options); + + options = {edges: {hidden: false}}; + createSampleNetwork(options); + }); + describe('Node', function () { it('has known font options', function () {