Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions app/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@ const { seo, docs } = useAppConfig()
const content = useDocsContent()
const route = useRoute()

const [{ data: navigation }, { data: sha }] = await Promise.all([
useAsyncData('navigation', () => content.value.client.navigation(), {
watch: [() => content.value.routeBase],
}),
useAsyncData(
() => `content-head:${content.value.apiBase}`,
() => $fetch<{ sha: string | null }>(`${content.value.apiBase}/head`).then(({ sha }) => sha),
{ default: () => null, watch: [() => content.value.apiBase] }
),
])
const { data: navigation } = await useAsyncData('navigation', () => content.value.client.navigation(), {
watch: [() => content.value.routeBase],
})

// Client-only: an SSR value gets baked into the page's ISR entry and would pin search to a stale commit.
const { data: sha } = useAsyncData(
() => `content-head:${content.value.apiBase}`,
() =>
$fetch<{ sha: string | null }>(`${content.value.apiBase}/head`)
.then(({ sha }) => sha)
.catch((error) => {
console.error('[search] could not resolve the content head', error)
return null
}),
{ server: false, watch: [() => content.value.apiBase] }
)

const nuxtApp = useNuxtApp()
const navTree = computed<NavigationItem[]>(() => prefixNavigation(navigation.value ?? [], content.value.routeBase))
Expand Down
5 changes: 2 additions & 3 deletions app/components/AppHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const content = useDocsContent()
const historyOpen = useVersionHistory()
const assistantOpen = useAssistant()
const navigation = useMainNavigation()
const { available: searchAvailable } = useSearch()
</script>

<template>
Expand All @@ -17,7 +16,7 @@ const { available: searchAvailable } = useSearch()

<template #right>
<UContentSearchButton
v-if="header?.search && searchAvailable"
v-if="header?.search"
:collapsed="false"
:icon="false"
class="text-muted font-normal hidden lg:inline-flex min-w-[150px]"
Expand Down Expand Up @@ -62,7 +61,7 @@ const { available: searchAvailable } = useSearch()
<div class="flex flex-col justify-between h-full">
<div class="flex flex-col gap-4">
<UContentSearchButton
v-if="header?.search && searchAvailable"
v-if="header?.search"
:collapsed="false"
size="xl"
class="w-full font-normal"
Expand Down
3 changes: 1 addition & 2 deletions app/components/AppSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const props = defineProps<{
navigation: NavigationItem[]
}>()

const { search, status, available } = useSearch()
const { search, status } = useSearch()

const appConfig = useAppConfig()

Expand Down Expand Up @@ -55,7 +55,6 @@ const groups = computed(() => {

<template>
<LazyUContentSearch
v-if="available"
:search="search"
:search-status="status"
:navigation="navigation"
Expand Down
10 changes: 5 additions & 5 deletions app/composables/useSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ function searchDebug(): boolean {
*/
export function useSearch() {
const content = useDocsContent()
const sha = inject<Ref<string | null>>('sha', ref(null))
const sha = inject<Ref<string | null | undefined>>('sha', ref(null))

/** What to hydrate from, or `null` when this route has nothing searchable. */
/** What to hydrate from, or `null` when this route has nothing searchable (yet). */
const target = computed(() => {
const isPreview = content.value.mode !== 'prod'
if (sha.value) return {
Expand All @@ -39,13 +39,14 @@ export function useSearch() {
return null
})

const available = computed(() => target.value !== null)

/**
* Load the database for the current target.
* No-ops if the target is unchanged.
*/
async function warmup(): Promise<void> {
// Not resolved yet — the `watch` below re-runs this once `sha` lands.
if (sha.value === undefined) return

const current = target.value

if (!current) {
Expand Down Expand Up @@ -87,6 +88,5 @@ export function useSearch() {
search,
status: readonly(status),
warmup,
available,
}
}
26 changes: 16 additions & 10 deletions app/error.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,22 @@ useSeoMeta({

const content = useDocsContent()

const [{ data: navigation }, { data: sha }] = await Promise.all([
useAsyncData('navigation', () => content.value.client.navigation(), {
watch: [() => content.value.routeBase],
}),
useAsyncData(
() => `content-head:${content.value.apiBase}`,
() => $fetch<{ sha: string | null }>(`${content.value.apiBase}/head`).then(({ sha }) => sha),
{ default: () => null, watch: [() => content.value.apiBase] }
),
])
const { data: navigation } = await useAsyncData('navigation', () => content.value.client.navigation(), {
watch: [() => content.value.routeBase],
})

// Client-only: an SSR value gets baked into the page's ISR entry and would pin search to a stale commit.
const { data: sha } = useAsyncData(
() => `content-head:${content.value.apiBase}`,
() =>
$fetch<{ sha: string | null }>(`${content.value.apiBase}/head`)
.then(({ sha }) => sha)
.catch((error) => {
console.error('[search] could not resolve the content head', error)
return null
}),
{ server: false, watch: [() => content.value.apiBase] }
)

// Matches app.vue: nav must be prefixed the same way search results are, so the palette can look them up.
const navTree = computed<NavigationItem[]>(() => prefixNavigation(navigation.value ?? [], content.value.routeBase))
Expand Down
Loading