Skip to content

Commit 93ab1c6

Browse files
committed
fix(prerender): edge cases in option caching
1 parent c33ae1d commit 93ab1c6

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/build/prerender.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,19 @@ export function setupPrerenderHandler(options: ModuleOptions, resolve: Resolver,
3232

3333
// Track hash-mode OG URLs whose source page isn't in the prerender graph.
3434
// These 404 at context.ts because the page's defineOgImage() never ran so
35-
// the hash:<hash> cache entry was never written. Clear the error so the build
36-
// doesn't fail, and warn once at the end of prerender so users can investigate.
35+
// the hash:<hash> cache entry was never written. Clear the error so nitro
36+
// doesn't add them to failedRoutes (which would fail the build).
37+
// Must use prerender:generate (fires before failedRoutes check), not
38+
// prerender:route (fires after — too late to prevent the build failure).
3739
const orphanedOgHashes: string[] = []
38-
nitro.hooks.hook('prerender:route', (route) => {
40+
nitro.hooks.hook('prerender:generate', (route) => {
3941
if (!route.error || route.error.statusCode !== 404)
4042
return
4143
if (!route.route.includes('/_og/s/o_'))
4244
return
4345
orphanedOgHashes.push(route.route)
44-
route.error = undefined
45-
route.contents = ''
46-
route.fileName = undefined
46+
route.skip = true
47+
delete route.error
4748
})
4849

4950
nitro.hooks.hook('prerender:done', async () => {

src/runtime/app/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ export function createOgImageMeta(src: string, input: OgImageOptions | OgImagePr
146146
if (component?.hash)
147147
urlOpts._componentHash = component.hash
148148
const result = buildOgImageUrl(urlOpts, extension, isStatic, defaults, ogImageConfig.security?.secret || undefined)
149+
// Propagate hash so prerender plugin can store it in prerenderOptionsCache
150+
if (result.hash)
151+
opts._hash = result.hash
149152
const resolvedUrl = joinURL('/', baseURL, result.url)
150153
const finalUrl = opts._query && Object.keys(opts._query).length
151154
? withQuery(resolvedUrl, { _query: opts._query })

0 commit comments

Comments
 (0)