Dropdown on mobile not populating with JS aync query data

I've got an async JS query that returns an array as expected (just an array of customer names).

The query is triggered on pageview event.

Those names are meant to be the options for a customer-lookup select field. When previewing the app in browser it seems to work fine.

But using it on my iPhone, the dropdown simply never populates. I feel like it has something to do with the query being async but I was under the impression that the field would update whenever the data changes, so wouldn't matter how long the query takes.

return (async () => {
  
  let { results, next } = await getAllClients.trigger(); // This makes the initial DB call, returns an array of names in 'results' and a 'next' property, which is the url for the next page of results or 'null' if none
  let array = results;
  let clientNames = [];

  async function getNextPage(url) { // if 'next' url exists, retrieve next page of results and concat to first set of results
    let response = await fetch(nextURL, {
      headers: {
        Authorization: "Token mySecretTokenHere",
      },
    });
    let {results, next} = await response.json();
    array = array.concat(results);

    if (next !== null) {
      getNextPage(next);
    } else {
      return array;
    }
  }

  if (next != null) {
    array = await getNextPage(next);
  } 
  
  array.map(({ Client }) => {
    clientNames.push(Client);
  });
  return clientNames;
})();

My select field is simply set to be the data result from that query:

Anybody got any ideas why it'd work fine in browser preview but not in mobile?

I see one odd thing here -- why are you not calling await getNextPage(next)? You may have a strange race condition.

Another issue I see is that nextURL is never declared.

If that's not the issue, I would recommend removing pieces of logic until you can get something working and then building back up from there.

Ah, the "nextURL" variable is defined/modified in a line right before that was removed to try to simplify things for the question. Didn't realize I'd left that reference in. So that's not the issue.

Not sure why getNextPage wasn't awaited but I just gave that a go and don't see any difference.

It very well could be some sort of race condition, seeing as how it works fine in browser preview but doesn't on mobile.

Hey @cluttercowboys! Are you still blocked here? Happy to try helping if so :slight_smile: