This code still triggers onReady twice on preview, even with the ‘work around’ I read in the forum:
import wixWindow from 'wix-window';
$w.onReady(function () {
if (wixWindow.rendering.env === "browser") {
console.log("onready");
}
})
Logging output:
Running the code for the Test page. To debug this code in your browser's dev tools, open gades.js.
onready
Running the code for the Test page. To debug this code in your browser's dev tools, open gades.js.
onready
Please see the article About the Page Rendering . As the section on Preventing Side Effects states:
" … your global page code and onReady() code will usually run twice, once in the backend and once in the browser. Generally, this is not a problem. In fact, it is used to load your page quicker. "
However, there are scenarios that might result in unwanted side effects. Refer to the above article to get the most out of Velo in your project.