All onClick() functions running twice Editor X Velo

I saw some posts about double running functions and I also know how Wix can bind functions twice because of server/client rendering. However the issue I am having today is insane. I am on my homepage and I can just add a button, add an onClick function, then simply write “console.log(variable)” and it will have two lines when tested. In preview mode it only has one line. All of my other functions are running twice as well.

From my research, it seems Wix glitches when duplicating pages, containers, or elements… so I am hoping there is a fix or way to clear out any previous bindings? I have already gone to each button and clicked the trash can icon to remove the bindings. Nothing I do seems to help my old stuff… I figured this was because of something having to do with duplicating… so I created the new button from scratch and my mind was blown when it executed twice as well.


Where activeSection is “login” in Firefox, so the console should only say “login” once, and as you can see, in the live page it shows twice:

What is even weirder is that it works perfectly in Preview mode!!! Just duplicates all functions in the live version. I have cleared out browser cache too just in case… but I already knew that wasn’t the issue because I changed the console.logs to different words.

Any help would be amazing, not sure what to do if I cannot troubleshoot this.

Matt

There was such a problem in the past.
What you can do:

  1. Contact Wix Customer Care and ask the to look into it.

  2. Meanwhile you can remove the event handlers of type export function and use $w(‘#elem’).onClick instead.
    For example:

$w.onReady(() => {
    $w('#button10').onClick(event => {
        console.log(activateState);
    })
})

This type on event listener doesn’t have this bug.

Dude!!! That fixed it! You saved me so much time. Thank you so much!

What if I am inside a repeater, and need to utilize the $item method?

$w.onReady(() => {
    $w('#repeater1').onItemReady(($i, iData, i)=>{
        $i('#button10').onClick((event)=> {
            console.log(iData);
        });
    });    
});
1 Like

this works, thank you sir!

1 Like