Code in Masterpage.js Running Twice (sometimes)

Question:
How can I prevent this from happening? I have code that needs to be run on every page, so masterpage.js is most convenient. *My code is already wrapped in

if wixWindow.rendering.env === "browser" { code here}

Product:
Wix Editor

What are you trying to achieve:
Database insert.

What have you already tried:
I’ve isolated the function to masterpage.js, so it is definitely an issue there. Everything is supposed to happen in the “browser” portion of the rendering cycle. I also haven’t personally been able to recreate the issue. It seems like it sometimes happens and sometimes doesn’t. There are several (probably 80%) duplicate insertions made typically between 0.9-1.5 seconds apart.

Can you share the code that is executing more than once?

I should have updated this. Turns out it was only happening when I would preview my site. Otherwise it doesn’t seem to be happening on the live site.

1 Like