NextJs App Router Infinite Loop when Index is not found #6560
-
Hey, We currently have an issue where we would get an infinite loop serverside and client side (depending which is catched by our error boundary) whenever an index is not found. This is just an edge case, since we are in the setup of a new domain, and the customer still needs to configure the correct indices. Anyways, I fixed it for now using the indexExists api on the searchClient.
Just wanted to ask if there is a better way to do this without having the use the full searchClient, since the lite client does not support this api. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
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. |
Beta Was this translation helpful? Give feedback.
That's indeed an interesting edge case. Another method to check if the index exists is by searching and catching the error:
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.