Closed trombonehero closed 6 years ago
Are you initialising after DOMContentLoaded on a div in the document tree?
That's a good question... I'm initialising when my Marko component "mounts" into the DOM: https://markojs.com/docs/components/#codeonmountcode
The div
element does exist at this point, but I'm not sure if DOMContentLoaded
has fired yet. Is there a simple way to check?
Just for reference, this issue occurs on Chrome but not Firefox.
Is there a simple way to check?
Log when loaded happens versus your mount
Ok, yes: DOMContentLoaded
fires before this error occurs. I don't see DOMContentReady
, but I do see DOMContentLoaded
before the "mount" event.
Going slightly further upstream, there is another potential fix for my immediate issue:
--- src/core/viewport.orig.js 2018-05-30 14:36:50.000000000 -0230
+++ src/core/viewport.js 2018-05-30 14:36:34.000000000 -0230
@@ -510,7 +510,10 @@
return ( _p.sizeCache = _p.sizeCache || ( container ? (function(){
let style = window.getComputedStyle( container );
- let val = function( name ){ return parseFloat( style.getPropertyValue( name ) ); };
+ let val = function( name ){
+ var str = style.getPropertyValue( name );
+ return (str == "") ? 0 : parseFloat(str);
+ };
return {
width: container.clientWidth - val('padding-left') - val('padding-right'),
However, I still think it'd be a good idea to ensure that all code paths through https://github.com/cytoscape/cytoscape.js/blob/master/src/math.js#L118 return something...
A zero area container does not make sense for a rendered instance. Adding workarounds to bounding box code doesn't sit right with me. It's just kicking the can farther down the road: Zero or infinite values aren't going to make the graph render properly or layout properly. It's a case of garbage in, garbage out.
Are you initialising after DOMContentLoaded on a div in the document tree?
If the first condition is true, the second is probably not. This seems like it may be a problem with the framework you're using. Perhaps it's giving you a pre-mount hook rather than a post-mount hook.
I don't think there's anything on this side that can properly resolve your issue. If you can build a minimal demo (no framework) that shows Cytoscape failing, please re-open this issue with the link.
Bug report
Environment info
Current (buggy) behaviour
The function
math.makeBoundingBox
can returnnull
when the inputbb
hasw: NaN
and nox2
ory2
. I see this happening when creating a newcytoscape
instance in Chrome in an as-yet-unsized DOM node (i.e., width = height = 0), wherecy.width()
andcy.height()
returnNaN
:This leads to an uncaught
TypeError
in Chrome. It doesn't seem to cause the same problem in Firefox...Desired behaviour
I expected not to see a
TypeError
and subsequent stoppage of the webpage.Minimum steps to reproduce
This is a bit tricky to reproduce without bringing in lots of context (e.g., Marko components). I think that the fix is pretty simple though:
Or, alternatively, add another
return { x1: Infinity /* ... */ }
to the end ofmath.makeBoundingBox()
.