Cannot read properties of undefined

87 views
Skip to first unread message

Bart Butenaers

unread,
Jan 29, 2024, 5:08:56 PMJan 29
to Blockly
Hi everybody,

Last month I received an issue from a user.  When he clicked an input field, an error occured in the logs and the block started sticking to his mouse cursor.  He added a recording in the Github issue that visualizes it.

Now we received the same issue from other users.  After some investigation we found out that the problem occurs starting from Blockly version 10.3.0

I was finally able to reproduce it:
  1. I click on the edit field.
  2. An error occurs in the console:

    undefined.png

  3. And then the block keeps sticking to the mouse cursor.
It fails at 406 because the div variable is undefined:

undefined2.png

But a similar issue also happens for e.g. a dropdown.  

Can it be that there is something general changed (e.g. about js dom loading or so) that has impact on all types of widgets?

P.S. We got some feedback in the past already about our application being a bit atypical, because it starts with a new workspace quite frequently.  Could that perhaps be somehow be impacted by such a change?

Thanks!
Bart

Beka Westberg

unread,
Jan 30, 2024, 11:58:30 AMJan 30
to blo...@googlegroups.com
Hiya Bart,

Is there anywhere where you're manually disposing of the widget div? In 10.3.0 we added a fix so that if you're injecting a new workspace, it will still reference the original widget div (since there's no reason to create a new one). I'm wondering if that reference is getting lost somewhere.

You can also check your page's elements for `blocklyWidgetDiv` to see if the element does exist or not.

Hopefully with a bit more info we can get this sorted!

Best wishes,
--Beka

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/1eb1dd42-ee7d-446f-9ed2-f97e02650e68n%40googlegroups.com.

Bart Butenaers

unread,
Jan 30, 2024, 4:38:09 PMJan 30
to Blockly
Hi Beka,

Thanks for joining (again)!

No the blocklyWidgetDiv is nowhere used in our code.
But we do dispose the workspace quite often. 

So my exception occurs because the containerDiv is undefined:
undefined3.png

So I had a look where this containerDiv should have been created:
undefined4.png

When I open my Node-RED web application, I arrive at line 67.  However after the workspace has been disposed and the inject function is called again, I arrive every time at the return statement of line 61.  So the containerDiv is not created again.

Do we have to dispose anything else perhaps?

Beka Westberg

unread,
Jan 31, 2024, 11:30:50 AMJan 31
to blo...@googlegroups.com
Hmm no the thing is you shouldn't have to dispose of anything. Because the container div never gets disposed, you should maintain a reference to it, regardless of whether the workspace itself is disposed or reinjected.

I'm wondering if perhaps you're not just injecting a new workspace, but you're using a new instance of Blockly which doesn't have a reference to the original widget div.

I've filed an issue to have `createDom` grab a reference to the widget div if it already exists.

Best wishes,
--Beka

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.

Bart Butenaers

unread,
Jan 31, 2024, 3:10:09 PMJan 31
to Blockly
Beka,
Ah yes, it is now coming back in my old brain...
Some time ago indeed your collegua Zoey figured out that we indeed indirectly create a new instance of Blockly, which previously already caused similar errors for us.
Thanks for logging the issue!  Really appreciated!
Reply all
Reply to author
Forward
0 new messages