Async function weird behavior

Hi All,

I am just trying to insert an entity into a table with async and await. Here is my code:

$w.onReady( async function () {
local.setItem(“templateId”, “0c256053-506c-491f-9c5a-58254c82f1fb”);
const action = await insertAction();
});
async function insertAction() {
const today = new Date();
const time = today.getTime();
let action = {
“accessTimestamp”: time,
“templateId”: local.getItem(“templateId”),
“ipAddress”: local.getItem(“ipAddress”)
};
const actions = await wixData.insert(“Actions”, action);
local.setItem(“functionofuID”, actions._id);
console.log("inside insert action: " + actions);
console.log("action id is " + local.getItem(“functionofuID”));
}

Every time I load this page, I am seeing two entities created with different ids. I don’t understand why its creating two entities when I am calling insertAction only once.

I don’t even see the logs twice. So I don’t know which part is creating second entity.

Any help on this please.

Thank you,
Divya.

The onReady() is running twice. Once in the backend and then again in the frontent. See the article Corvid: About the Page Rendering Process .