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

EdgesHandler._addMissingEdges Cannot read property 'forEach' of null #3562

Open
Stexxen opened this issue Oct 12, 2017 · 27 comments
Open

EdgesHandler._addMissingEdges Cannot read property 'forEach' of null #3562

Stexxen opened this issue Oct 12, 2017 · 27 comments

Comments

@Stexxen
Copy link
Contributor

Stexxen commented Oct 12, 2017

On upgrading from 4.20.1 to 4.21. I'm now seeing this error in the console.
image

This appears to be caused by #3516 and discussed in #3500

Exception is raised at this line - https://github.com/almende/vis/blob/master/lib/network/modules/EdgesHandler.js#L468

Can someone explain if these changes are meant to cause this error and does it require different data structures now?

@wimrijnders
Copy link
Contributor

Aaaand the first issue for release 4.21.0 is in!

No, that's not supposed to happen. The data structure is exactly the same as previous version.

But this means that there is no DataSet instance for edges defined....is it remotely possible that you do not pass any edge data in?

In any case, this will need a fix.

@wimrijnders
Copy link
Contributor

Oops sorry wrong button.

@wimrijnders
Copy link
Contributor

I'm trying to reproduce this through the standard API without much success. Could you give me some example code that shows this problem?

@Stexxen
Copy link
Contributor Author

Stexxen commented Oct 13, 2017

will do.

@Stexxen
Copy link
Contributor Author

Stexxen commented Oct 13, 2017

Tracked it down. (Well how to cause it anyways.....)

Here's an example using the Getting Started Code
https://plnkr.co/edit/fczlRG6U9El1rd3xLFx6?p=preview

The problem appears to be related to setting an options field.

var options = {
  "nodes":{
    "physics":true
  }
};

triggers the bug, but the weird thing is that it doesn't matter what the value is

var options = {
  "nodes":{
    "physics":false
  }
};

also triggers the bug

Whereas

var options = {
  "nodes":{
    // "physics":true
  }
};

Does not.

@wimrijnders
Copy link
Contributor

OK, got it. Can reproduce. Thanks for your sleuthing!

@wimrijnders
Copy link
Contributor

wimrijnders commented Oct 13, 2017

That's a nice interplay of internal 'features'. The options get handled before the data and physics option triggers a dataChanged event. But there is no data at that point.

All this can be solved with a strategically placed test on null. But I'll delve a bit deeper to see if there are further consequences. Bet you a beer icon same thing happens with edges.physics.

@Stexxen
Copy link
Contributor Author

Stexxen commented Oct 13, 2017

Yep edges.physics triggers it as well.

🍺

:-)

@wimrijnders
Copy link
Contributor

Yay! One for the collection.

@wimrijnders
Copy link
Contributor

Was introduced in this version; had to check. We're planning a quick release in 2 weeks time precisely for this kind of shiissues. Thanks for reporting!

@wimrijnders
Copy link
Contributor

This is where the dataChanged is triggered:

if (options.hidden !== undefined || options.physics !== undefined) {
this.body.emitter.emit('_dataChanged');
}

Let's try options.hidden as well, shall we?

explosion3

@wimrijnders
Copy link
Contributor

Best thing to do is to block handling of dataChanged as early as possible if there is no data. I'm on it.

wimrijnders added a commit to wimrijnders/vis that referenced this issue Oct 13, 2017
…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.
@wimrijnders
Copy link
Contributor

Wrt to your comment on the PR: it doesn't matter what you fill in for physics, the error will be triggered. So 'false' is as good as any. You noticed this yourself.

@Stexxen
Copy link
Contributor Author

Stexxen commented Oct 13, 2017

yeah sorry I deleted it as soon as I wrote it. doh!

@wimrijnders
Copy link
Contributor

No worries. Here, have a beer (icon): 🍺

yotamberk pushed a commit that referenced this issue Oct 13, 2017
…ation (#3568)

* Network: Prevent crash when dataChanged is triggered during initial setting of options

Fixes #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.

* Edited comment
@justinharrell
Copy link
Contributor

Sorry about this one, should have known better than skip a null check.

@wimrijnders
Copy link
Contributor

wimrijnders commented Oct 13, 2017

@justinharrell not a problem, shit happens. It wasn't obvious at all that this could happen. In any case, it's shared guilt, since I could have noted it when reviewing.

I'm just glad we got this so early (thanks OP), in two weeks time with the next release it'll be history.

@dakk
Copy link

dakk commented Oct 19, 2017

I'm still getting the error using a DataView instead of using an array or DataSet; the problem is not a null data but a missing forEach on DataView. I expected that DataView inherits forEach from DataSet, but the forEach method is not present on DataView.

I think we need to put something like:

// copy foreach functionality from DataSet
DataView.prototype.forEach = DataSet.prototype.forEach;

here: https://github.com/almende/vis/blob/master/lib/DataView.js#L391

@justinharrell
Copy link
Contributor

Oops again, thought I checked and made sure Dataview had forEach. Definitely makes sense to me that it should.

@dakk
Copy link

dakk commented Oct 22, 2017

Is it necessary a new issue @justinharrell ? This was related to a null reference, while my report is about missing method

watho added a commit to watho/visjs that referenced this issue Dec 22, 2017
@dhermanns
Copy link

Hi! Any idea when the fix will be released?

@romak1984
Copy link

Any progress with this?

@ajs-88
Copy link

ajs-88 commented Feb 25, 2018

Any progress guys?

@ajs-88
Copy link

ajs-88 commented Feb 25, 2018

Guys, I tried a work around to disable physics and it worked,

`
var data = {
nodes: nodes,
edges: edges
};

    var options = {
        nodes: {
            shape: 'circle'
        },
        edges: {
            arrows: 'to'
        },
        physics: false
    };
    var network = new vis.Network(container, data, options);

`

@amarvin
Copy link

amarvin commented Apr 13, 2018

My workaround is to keep using the older Vis.js version 4.20.1

@burgalon
Copy link

Thanks @amarvin

@JanTheHun
Copy link

JanTheHun commented Aug 29, 2018

The bug still exists.

@aruljane-s workaround doesn't seem to work for me. data is definitely not null.

Any suggestions? This bug is almost a year old, is it possible to fix it somehow?

EDIT:
sorry, my mistake, @aruljane-s solution (moving physics field one level up) DOES work!

EDIT2:
maybe the documentation should be updated?

burgalon added a commit to burgalon/react-graph-vis that referenced this issue Sep 5, 2018
@mojoaxel mojoaxel added this to the Minor Release v4.22 milestone Feb 18, 2019
mojoaxel pushed a commit to visjs/vis_original that referenced this issue Jun 9, 2019
…ation (almende#3568)

* Network: Prevent crash when dataChanged is triggered during initial setting 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.

* Edited comment
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests