Skip to content

Commit 1c332ef

Browse files
committed
fix: handle deferred 404
1 parent 4cc1bc8 commit 1c332ef

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

app/composables/npm/useResolvedVersion.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ export function useResolvedVersion(
1515
const data = await $fetch<ResolvedPackageVersion>(url)
1616
return data.version
1717
},
18-
{ default: () => null },
18+
{ default: () => undefined },
1919
)
2020
}

app/pages/package/[[org]]/[name].vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,18 @@ const { data: resolvedVersion, status: resolvedStatus } = await useResolvedVersi
215215
requestedVersion,
216216
)
217217
218+
if (import.meta.server && !resolvedVersion.value && resolvedStatus.value === 'success') {
219+
throw createError({
220+
statusCode: 404,
221+
statusMessage: $t('package.not_found'),
222+
message: $t('package.not_found_message'),
223+
})
224+
}
225+
218226
watch(
219227
[resolvedStatus, resolvedVersion],
220228
([status, version]) => {
221-
if (version === null && status === 'success') {
229+
if (!version && status === 'success') {
222230
showError({
223231
statusCode: 404,
224232
statusMessage: $t('package.not_found'),

modules/isr-fallback.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default defineNuxtModule({
3131
const outputPath = resolve(nitro.options.output.serverDir, '..', path, htmlFallback)
3232
mkdirSync(resolve(nitro.options.output.serverDir, '..', path), { recursive: true })
3333
writeFileSync(outputPath, spaTemplate)
34-
writeFileSync(outputPath.replace(htmlFallback, jsonFallback), '[{}]')
34+
writeFileSync(outputPath.replace(htmlFallback, jsonFallback), '[]')
3535
}
3636
})
3737
})

0 commit comments

Comments
 (0)