Hi,
I make an Insert into a collection on my $w.onReady( function ()
I want the insert to happen only once so i’m using the rendering API
I’ve tried with
if (wixWindow.rendering.env === “browser”)
but it still inserts my row twice (most of the time)
and I also tried with
if (wixWindow.rendering.renderCycle === 1)
sometimes it added the row twice and sometimes it didn’t add it at all
Any suggestions?
Please post your code or the editor link to your site so we can inspect.
$w.onReady( function () {
if (wixWindow.rendering.env === “browser”) {
wixData.query("giftRequests")
.eq("_id",requestReceived)
.find()
.then( (Results) => {
let requestDataInsert = {
“title”: Results.items[0].title,
“requestId”: Results.items[0].request,
“giverAnswer”: “מעוניין לבדוק”,
“comment”: Results.items[0].comment,
“answerSent”: false
};
wixData.insert("requestData", requestDataInsert)
.then( (results) => {
console.log("properly inserted");
})
. **catch** ( (err) => {
console.log(err);
} );
})
}
$w.onReady( function () {
if (wixWindow.rendering.env === “browser”) {
wixData.query("giftRequests")
.eq("_id",requestReceived)
.find()
.then( (Results) => {
let requestDataInsert = {
“title”: Results.items[0].title,
“requestId”: Results.items[0].request,
“giverAnswer”: “מעוניין לבדוק”,
“comment”: Results.items[0].comment,
“answerSent”: false
};
wixData.insert("requestData", requestDataInsert)
.then( (results) => {
console.log("properly inserted");
})
. **catch** ( (err) => {
console.log(err);
} );
})
}
I believe that check you want to make is this:
if (wixWindow.rendering.renderCycle === 1) {
// your query and insert code
}
By checking for renderCycle === 1, you can be sure that the insert only occurs once.
You can find more information about rendering in the article Wix Code: About the Page Rendering Process. See the section on Adding an Item to a Collection for your usage case.
@yisrael-wix Yes, I also tried it but sometimes it didn’t insert my row at all and sometimes it inserted it once and sometimes twice
@anatarad Are you testing in Preview or Live? Be aware that: Rendering never occurs server-side when previewing your site .
@yisrael-wix Yes, of course
Only live
@anatarad Please post the editor URL of your site. Only authorized Wix personnel can get access to your site in the editor. Please include the name of the page involved. Also, please explain how to perform the action.
Hello
I also suffered from this issue.
I added the following code:
$w.onReady(() => {
console.log(wixWindow.rendering.env);
console.log(wixWindow.rendering.renderCycle);
});
As you can see in the attached image, it happens twice no matter what.

Also according some place I ready the "renderCycle " is obsolete!
Why do I get “browser” twice??
How can it be resolved that the action will happen only once??
Thanks!