Disconnected Function node runs on page mount [Bug?]

I have a function node in one of the pages that’s currently, completely disconnected.
Yet, it gets executed whenever the page mounts, which is undesirable and unexpected.

Is it a bug?

Hi Shrey
I see you already had your question answered on Discord, but I’ll reply my take here too so other users in the future can find the answer too.

No, this is not a bug and isn’t always as unexpected/undesirable as you suggest, hehe :slight_smile:
By default, functions run as the component they exist in are rendered, unless something is connected to the run port - Connecting a signal to run this will prevent autorun, and only run the function when a signal is sent to the run port.

However, I found a little trick you can use if you want to manually disable/enable autorun on functions (see screenshot below), and you don’t want to delete the function entirely. If you use a Switch-node as a signal input to the function and connect “Switched to On” to the run port, you can manually set the Switch to On/Off, depending if you want to autorun the function or not.

This works because the State of the Switch is evaluated as the component it exists in is rendered, just like the function normally would. However, in this case the Switch instead acts as a gatekeeper to allow whether or not the function should autorun.

In the screenshot below, autorun is set to On, but if you uncheck the box by the red arrow, it’ll be set to Off.

Hope this helps! :slight_smile:

Best regards, Victor from Noodl

1 Like

That’s a neat trick. Thanks!