Skip to content

Commit

Permalink
Network: Prevent crash when dataChanged is triggered during initial s…
Browse files Browse the repository at this point in the history
…etting of options

Fixes almende#3562.

Options `hidden` and `physics` can emit a `_dataChanged` event within `setOptions()`.
If this happens when setting options during the initialization of the `Network` instance, this leads
to an error thrown, because there is no DataSet instance  connected yet to the instance.

This bug was introduced in `v4.21.0`. Unit tests have been added for this case.
  • Loading branch information
wimrijnders committed Oct 13, 2017
1 parent c56fa19 commit f3d6ee4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/network/modules/EdgesHandler.js
Expand Up @@ -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) => {
Expand Down
21 changes: 21 additions & 0 deletions test/Network.test.js
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

0 comments on commit f3d6ee4

Please sign in to comment.