How do I get my repeater.itemReady(...) text to show up consistently in preview?

I have a repeater that isn’t showing correctly in preview.

I manipulate the text with data from my dataset and from a wixData query, so I populate the repeater text with the following code:

export async function myRepeater_itemReady($item, itemData, index) {
    $item('#repeaterText').html = await buildHtml(...);
}

In the editor, it appears like this (all is good):

On the website, it shows my built HTML just fine:

But in preview, it looks like this:


How do I get this to show up properly in preview?

Hi. I doubt someone will be able to answer this question without looking into the specific case in preview Vs live.

Excellent! How do I help someone look into the specific case?

Another thing:
If you use bind data from the database, you should know, that in preview mode it takes the data from the sandbox collection, so make sure the relevant data is in the sandbox as well.

Upon testing further I believe this is just a bug in the way Velo renders previews. It appears that it assumes that the rendering is already completed for the text fields that were rendered in the editor, and only runs the “Repeater_ItemReady(…)” events for any items not rendered in the editor.

Since the editor is limited to 12 items, and my dataset contains 17, only the last 5 “Repeater_ItemReady(…)” events run.

This is a bug. Since “Repeater_ItemReady(…)” doesn’t run in the editor, it MUST run on every line in the preview for the preview to be accurate.

I can’t say I understood the issue…

@jonatandor35 I thought i was the only one, who didn’t understand the issue :sweat_smile:

I’m sorry that I’m being unclear. Allow me to show how you can reproduce the error.

  1. Create a collection with more than 12 items.

  1. Create a new page on your site.
  2. Add a repeater to your new page.
  3. Add a dataset attached to the new collection to your new page.
  4. Set the number of items to display to 20.
  5. Connect your dataset to your repeater.
  6. Make sure your repeater has at least 2 text fields.
  7. Attach one text field to a column of your dataset.
  8. Set the other text field to “This should disappear in preview”.
  9. Create an “itemReady” event for your repeater.
  10. In the “itemReady” event, set the second text field to “This should be visible in preview”.

  1. Click Preview. The first twelve rows won’t change. The rows beyond will change.

  1. Publish your site with it’s new page
  2. Sync your database to live
  3. View the live page. All fields will be populated with the text “This should be visible in preview”.

The preview bug is in step 12. The itemReady event is not firing in preview.

You’re not doing it right.
I’m not sure what exactly you’re trying to do, but if you want the onItemReady() to run after the data gets bound via the editor connection, then you need to do something like this:

$w.onReady(() => {
    $w("#dataset1").onReady(() => {
        $w("#reapeater1").forEachItem(($item, itemData, index) => {
        $item("#text1").text = "something";
        }) 
    })
})
1 Like

@jonatandor35 Thank you for this workaround.

To say I’m not doing it right is incorrect. This is exactly how binding ItemReady via the editor is expected to behave in preview (as evidenced by how it behaves in live). To have it behave otherwise is a bug.

@nate See the documentation ;
“Note: When using a dataset to populate the contents of your repeated items, the onItemReady() callback function is triggered before the dataset populates the values of your page elements. Therefore, element values that you set using onItemReady() may be overridden when the dataset is ready…”

That’s why you couldn’t do it your way.

@jonatandor35 As the documentation states:
“When the data property is set for the repeater, the onItemReady function is automatically triggered.”
This is what isn’t working in the Preview. If you’re suggesting that the data property is being set while I’m still in the editor , that design doesn’t meet my expectations. That would guarantee that preview and live will behave differently from each other.

For what it’s worth, I’m perfectly happy to accept that my expectations differ from the way Velo has been designed. My expectations are that the data property will be set after I press the preview link, which would allow preview to behave like live. The current behavior doesn’t meet those expectations.