docs(fetchComponentMeta): handle case where component doesn't exist

This commit is contained in:
Benjamin Canac
2024-07-11 17:14:45 +02:00
parent c712e2e682
commit 810ea32bf8

View File

@@ -13,9 +13,7 @@ export async function fetchComponentMeta(name: string): Promise<{ meta: Componen
return state.value[name]
}
// Store promise to avoid multiple calls
// add to nitro prerender
// Add to nitro prerender
if (import.meta.server) {
const event = useRequestEvent()
event.node.res.setHeader(
@@ -23,8 +21,12 @@ export async function fetchComponentMeta(name: string): Promise<{ meta: Componen
[event.node.res.getHeader('x-nitro-prerender'), `/api/component-meta/${name}.json`].filter(Boolean).join(',')
)
}
// Store promise to avoid multiple calls
state.value[name] = $fetch(`/api/component-meta/${name}.json`).then((meta) => {
state.value[name] = meta
}).catch(() => {
state.value[name] = {}
})
await state.value[name]