Good day, I'm using fabricjs
, and it works well for me.
I did however recently come across a JavaScript thing I cannot explain, and that I only detected on fabricjs
(across all browsers).
Note: I am using 1.7.11
of fabricjs
.
It occurs on mouse:out
events.
It's only side-effect is to bloat the browser console with:
Uncaught TypeError: Cannot read property 'fire' of null at klass._fireOverOutEvents (fabric.js:9717) ...
It goes like this:
This is vanilla fabric.js
(i.e. not my code).
As you can see, target
is undefined
, so the if
block is not executed. So far, that is expected. Now for the odd part.
this._hoveredTarget
is null
(see debugger view below).
The else if
block should not be executed, yet it is.
Debugging view of falsy "else if" being executed
I tried to fix it with variants like this._hoveredTarget !== null
and this._hoveredTarget != null
, but it still goes there when this._hoveredTarget
is null
.
I never saw this before. Any idea?
Ok this cannot happen just because a bug in the code. an IF is an IF. What can happen is that you have some event handling on
mouse:out
that is happening before that line that is erroring and that event handler is deleting the reference tothis._hoverTarget
.This is still a bug in my opinion since if custom code is allowed the condition must be checked again before accessing the variable as an object.
Current version of fabricJS 1.7.17 has a different code in place:
this.hoveredTarget is saved as reference immediately so that whatever it happens to hoveredTarget you are safe.
You should upgrade maybe.