mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 20:19:34 +01:00
docs(fetchComponentMeta): handle case where component doesn't exist
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user