fix(nuxt): handle errors loading app manifest (#27441)

This commit is contained in:
Daniel Roe 2024-06-07 10:56:48 +01:00 committed by GitHub
parent 7b4f1a8b72
commit e109d81d40
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -24,9 +24,13 @@ function fetchManifest () {
if (!isAppManifestEnabled) {
throw new Error('[nuxt] app manifest should be enabled with `experimental.appManifest`')
}
manifest = $fetch<NuxtAppManifest>(buildAssetsURL(`builds/meta/${useRuntimeConfig().app.buildId}.json`))
manifest = $fetch<NuxtAppManifest>(buildAssetsURL(`builds/meta/${useRuntimeConfig().app.buildId}.json`), {
responseType: 'json',
})
manifest.then((m) => {
matcher = createMatcherFromExport(m.matcher)
}).catch((e) => {
console.error('[nuxt] Error fetching app manifest.', e)
})
return manifest
}
@ -48,5 +52,14 @@ export async function getRouteRules (url: string) {
return defu({} as Record<string, any>, ..._routeRulesMatcher.matchAll(url).reverse())
}
await getAppManifest()
if (!matcher) {
console.error('[nuxt] Error creating app manifest matcher.', matcher)
return {}
}
try {
return defu({} as Record<string, any>, ...matcher.matchAll(url).reverse())
} catch (e) {
console.error('[nuxt] Error matching route rules.', e)
return {}
}
}