Is your code running twice on your site’s pages? For example, are items being inserted into a collection twice?
This can happen because of how Wix renders pages on your site. You can read more about the rendering process here.
In short, setting up a page involves running both global page code and any code in your onReady() function. This code is run both on the backend and also in the browser--this helps load your page quicker. However, there are times when the results of your code might be experienced twice, if you don’t add code, such as the Rendering APIs, to prevent this from happening.
But here is another trick you can use to avoid “double vision.”
Calling any function in a JavaScript setTimeout from within your onReady() function makes sure the function won't run in the backend!
Only code in the onReady() itself is run during rendering. Code timed to run later is not.
In the following sample code snippet, our hideAll() function runs during initial page rendering. It doesn’t matter if hideAll() runs twice, because the effect will be the same. Our pageSetup() function is scheduled to run later, not during initial page rendering.
$w.onReady(function () {
hideAll();
setTimeout(pageSetup, 0);
});