Query doesn't load when refresh but works when pressing a button

I’m running into a very weird bug. I created a table of ideas and for each ideas I’m looking for some data in another firestore query called values to get the name instead of the id.

On preview mode, when I first load the page I have an error saying it’s undefined but when I trigger a button to run the query it works.

Here is my transformer’s data:

const values = {{getValues.data}};

return data ? data.map(idea => {
  const ideaValues = idea.values || [];
  const newThing = ideaValues.map(value => {
    const element = values.find(v => v._id === value );
    return element ? element.name : 'NOT FIND';
  })
  idea.newValues = newThing.join(', ')
  
  return idea;
}) : [];

Any idea why it doesn’t load at first?

Hey @cdedreuille! Previewing a query doesn’t actually update the query’s properties in a Retool app - you’ll need to click “run” for that to happen. Have you set the query to run when inputs change, or only manually?

Sorry I didn’t mean previewing the data but showing the page in view mode.
Also the query is set to run when inputs change.

The weird thing is that I have different behaviours between production and staging. On production where I have a larger data it’s all fine but in staging with just a few documents I the data doesn’t load at first. I need to actually run it.

I think the problem is that the query I put in my transformer isn’t initialised when you load the page therefore it can’t grab the data and crash the query. When I press run it works just fine because I imagine the data is already loaded.

@justin I solved the problem by moving my transformer outside of the query itself and applying the transformer instead of the query itself to our table. So now when I load the page, I don’t have the bug anymore.

So I guess there’s some issue on your side with the order queries are loading inside queries’ transformers, but at least I know how to fix it now.

I’m wondering if there might be some race condition here where with the larger production data set, that first query takes a little longer to run and isn’t available in the second.

Was the getValues query set to run on load and then the second query set to run “when manually triggered” and selected to run on success of the first one? If the second query is set to run “when inputs change” also then it would run at the same time as the first query.