Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

Network: Prevent crash when dataChanged is triggered during initialization #3568

Merged
merged 2 commits into from
Oct 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/network/modules/EdgesHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,12 @@ class EdgesHandler {
* @private
*/
_addMissingEdges() {
let edges = this.body.edges;
let edgesData = this.body.data.edges;
if (edgesData === undefined || edgesData === null) {
return; // No edges DataSet yet; can happen on startup
}

let edges = this.body.edges;
let addIds = [];

edgesData.forEach((edgeData, edgeId) => {
Expand Down
21 changes: 21 additions & 0 deletions test/Network.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down