# Interesting behaviour of empty Blockly node

**URL:** <https://discourse.nodered.org/t/interesting-behaviour-of-empty-blockly-node/82178>\
**Category:** General\
**Created:** [19 October 2023 08:29 UTC](https://discourse.nodered.org/t/interesting-behaviour-of-empty-blockly-node/82178 "2023-10-19T08:29:38Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [19 October 2023 08:29 UTC](https://discourse.nodered.org/t/interesting-behaviour-of-empty-blockly-node/82178/1 "2023-10-19T08:29:38Z")

</div>

Just while I'm testing other stuff out - I created the simplest flow with nothing in the Blockly node and just on a whim - pressed the inject - and was surprised that the timestamp went thru

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/1/51d472d79abf32a312554d9598f245f5b5d9df82.png)

Tried the same with empty function and it didn't

Like I say - interesting behaviour - I'll get back onto testing the big stuff 🙂

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [19 October 2023 08:49 UTC](https://discourse.nodered.org/t/interesting-behaviour-of-empty-blockly-node/82178/2 "2023-10-19T08:49:24Z")

</div>

> [@cymplecy](#):
>
> Tried the same with empty function and it didn't

And it shouldn't, if it's _empty_! 🤓

However, a newly created function node contains `return msg;` by default, so the behaviour is consistent if you don't empty it manually. 😉

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [19 October 2023 08:51 UTC](https://discourse.nodered.org/t/interesting-behaviour-of-empty-blockly-node/82178/3 "2023-10-19T08:51:31Z")

</div>

I am comparing like with like - I cleared the function node 🙂

> [@kuema](#):
>
> However, a newly created function node contains `return msg;` by default, so the behaviour is consistent if you don't empty it manually

That could be Bart's intention - he'll call it a feature 🙂

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [19 October 2023 09:00 UTC](https://discourse.nodered.org/t/interesting-behaviour-of-empty-blockly-node/82178/4 "2023-10-19T09:00:33Z")

</div>

I've never tried the Blockly nodes, but if it's empty, I wouldn't expect it to output anything. 🤔  
Maybe you found a bug... 😉

Whereas for an empty function, that would be the correct behaviour, because your script isn't returning any value.

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [19 October 2023 09:06 UTC](https://discourse.nodered.org/t/interesting-behaviour-of-empty-blockly-node/82178/5 "2023-10-19T09:06:24Z")

</div>

It's a very slight bug and 99.999% of time msg.payload will be altered by user code so in practice, it'll never cause a real issue. 🙂

Especially for us muggle coders who can't spull Javaship 🙂

It's probably been there for past 5 years but only noticed it today during testing a more complex issue

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [21 October 2023 07:45 UTC](https://discourse.nodered.org/t/interesting-behaviour-of-empty-blockly-node/82178/6 "2023-10-21T07:45:34Z")

</div>

> [@cymplecy](#):
>
> That could be Bart's intention - he'll call it a feature 🙂

Hmm this one seems to be a hidden feature, not a bug 😋

1. When you add a _ **new** _ Blockly node to your flow, the default value of the javascript (see [here](https://github.com/bartbutenaers/node-red-contrib-blockly/blob/master/blockly.html#L662)) code is `return msg;`. And that code is indeed used in the VM that we start:

2. However when you change e.g. the timeout setting in your node, the node is deployed again. The javascript tab is still empty (as before), but now the (empty) generated code is deployed:

I think it is better if the default javascript code `return msg;` is replaced by no code, to match the default core Function node behaviour.

BTW the fact that the default `return msg;` javascript code is not showed in our Javascript tabsheet, is indeed a bug 🤫

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [21 October 2023 07:51 UTC](https://discourse.nodered.org/t/interesting-behaviour-of-empty-blockly-node/82178/7 "2023-10-21T07:51:21Z")

</div>

> [@BartButenaers](#):
>
> BTW the fact that the default `return msg;` javascript code is not showed in our Javascript tabsheet, is indeed a bug 🤫

I mean when we initialize the (generated) javascript code to `return msg;`, we should also initialize the workspace xml to a Blockly workspace containing a block that sends the message to the output. Because the Blockly diagram and the generated Js code should always be in sync, which is now not the case: we have Js code for an empty Blockly workspace. That is not correct.

But it is more easy if we just start in a new Blockly node from an empty workspace and corresponding no Js code.

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [21 October 2023 07:52 UTC](https://discourse.nodered.org/t/interesting-behaviour-of-empty-blockly-node/82178/8 "2023-10-21T07:52:44Z")

</div>

@cymplecy: Really nice catch that you find this one during testing!!  
Only a pity that it took you five years... 🤣

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [21 October 2023 10:08 UTC](https://discourse.nodered.org/t/interesting-behaviour-of-empty-blockly-node/82178/9 "2023-10-21T10:08:03Z")

</div>

Tested your update on GitHub - works - no longer returns anything if blank

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [21 October 2023 10:08 UTC](https://discourse.nodered.org/t/interesting-behaviour-of-empty-blockly-node/82178/10 "2023-10-21T10:08:59Z")

</div>

Thanks Simon for confirming this!!  
Enjoy your weekend!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [20 December 2023 10:09 UTC](https://discourse.nodered.org/t/interesting-behaviour-of-empty-blockly-node/82178/11 "2023-12-20T10:09:52Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
