# rendering 

**URL:** <https://forum.wixstudio.com/t/rendering/15049>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [December 31, 2018, 5:09pm UTC](https://forum.wixstudio.com/t/rendering/15049 "2018-12-31T17:09:38Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![anatarad](https://avatars.discourse-cdn.com/v4/letter/a/ccd318/32.png) [@anatarad](https://forum.wixstudio.com/u/anatarad)\
**Post date:** [December 31, 2018, 5:09pm UTC](https://forum.wixstudio.com/t/rendering/15049/1 "2018-12-31T17:09:38Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [January 1, 2019, 6:48am UTC](https://forum.wixstudio.com/t/rendering/15049/2 "2019-01-01T06:48:11Z")

</div>

Please post your code or the editor link to your site so we can inspect.

---

<div class="post-metadata">

**Author:** ![anatarad](https://avatars.discourse-cdn.com/v4/letter/a/ccd318/32.png) [@anatarad](https://forum.wixstudio.com/u/anatarad)\
**Post date:** [January 1, 2019, 10:01am UTC](https://forum.wixstudio.com/t/rendering/15049/3 "2019-01-01T10:01:07Z")

</div>

$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); 
                                    } );  
                }) 

```

}

---

<div class="post-metadata">

**Author:** ![anatarad](https://avatars.discourse-cdn.com/v4/letter/a/ccd318/32.png) [@anatarad](https://forum.wixstudio.com/u/anatarad)\
**Post date:** [January 1, 2019, 10:01am UTC](https://forum.wixstudio.com/t/rendering/15049/4 "2019-01-01T10:01:15Z")

</div>

$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); 
                                    } );  
                }) 

```

}

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [January 1, 2019, 10:30am UTC](https://forum.wixstudio.com/t/rendering/15049/5 "2019-01-01T10:30:05Z")

</div>

I believe that check you want to make is this:

```javascript
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.

---

<div class="post-metadata">

**Author:** ![anatarad](https://avatars.discourse-cdn.com/v4/letter/a/ccd318/32.png) [@anatarad](https://forum.wixstudio.com/u/anatarad)\
**Post date:** [January 1, 2019, 10:32am UTC](https://forum.wixstudio.com/t/rendering/15049/6 "2019-01-01T10:32:34Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [January 1, 2019, 10:36am UTC](https://forum.wixstudio.com/t/rendering/15049/7 "2019-01-01T10:36:14Z")

</div>

@anatarad Are you testing in Preview or Live? Be aware that: _Rendering never occurs server-side when previewing your site_ .

---

<div class="post-metadata">

**Author:** ![anatarad](https://avatars.discourse-cdn.com/v4/letter/a/ccd318/32.png) [@anatarad](https://forum.wixstudio.com/u/anatarad)\
**Post date:** [January 1, 2019, 11:00am UTC](https://forum.wixstudio.com/t/rendering/15049/8 "2019-01-01T11:00:34Z")

</div>

@yisrael-wix Yes, of course 🙂 Only live

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [January 1, 2019, 11:24am UTC](https://forum.wixstudio.com/t/rendering/15049/9 "2019-01-01T11:24:57Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![galiliyaniv](https://avatars.discourse-cdn.com/v4/letter/g/5f9b8f/32.png) [@galiliyaniv](https://forum.wixstudio.com/u/galiliyaniv)\
**Post date:** [October 21, 2019, 10:03am UTC](https://forum.wixstudio.com/t/rendering/15049/10 "2019-10-21T10:03:43Z")

</div>

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.

![](https://us1.discourse-cdn.com/wix/original/3X/2/0/209815150f7e657bf3a216a58c94f3a66bb54ebf.png)

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!
