Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Load search results lazily so navigation doesn't wait for the API (#5698)

Olga Bulat13289467f2b7
diff --git a/frontend/src/pages/search.vue b/frontend/src/pages/search.vue
index 125286c67..d94690633 100644
--- a/frontend/src/pages/search.vue
+++ b/frontend/src/pages/search.vue
@@ -3,8 +3,8 @@ import {
definePageMeta,
navigateTo,
showError,
- useAsyncData,
useHead,
+ useLazyAsyncData,
useNuxtApp,
useRoute,
} from "#imports"
@@ -114,7 +114,9 @@ const handleLoadMore = async () => {
await fetchMedia({ shouldPersistMedia: true })
}
-await useAsyncData(
+// Lazy, so that navigating to the search page doesn't wait for the API
+// response. The results grid shows a loading state until the results arrive.
+useLazyAsyncData(
"search",
async () => {
if (nuxtApp.isHydrating) {