Skip to content

NextJs App Router Infinite Loop when Index is not found #6560

Closed Answered by Haroenv
wesleyjanse asked this question in Q&A
Discussion options

You must be logged in to vote

That's indeed an interesting edge case. Another method to check if the index exists is by searching and catching the error:

async function indexExists(indexName) {
  try {
    await search([{ indexName }]);
  } catch (e) {
    if (
      e.name === 'ApiError' &&
      e.message === `Index ${indexName} does not exist`
    ) {
      return false;
    }
    throw e;
  }
  return true;
}

There's other methods as well, like using useInstantSearch with the catchError option, although that might still cause server side rendering problems if it only fails on server and not on client.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@wesleyjanse
Comment options

Answer selected by Haroenv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants