fix(nuxt): ignore failures to access asyncContext in environments without it

This commit is contained in:
Daniel Roe 2024-03-17 20:12:45 +01:00
parent 0d9c63b828
commit 523db1a197
No known key found for this signature in database
GPG Key ID: CBC814C393D93268

View File

@ -44,12 +44,15 @@ export default (nitroApp: NitroApp) => {
})
nitroApp.hooks.hook('afterResponse', () => {
const ctx = asyncContext.use()
const ctx = asyncContext.tryUse()
if (!ctx) { return }
return nitroApp.hooks.callHook('dev:ssr-logs', { logs: ctx.logs, path: ctx.event.path })
})
// Pass any logs to the client
nitroApp.hooks.hook('render:html', (htmlContext) => {
const ctx = asyncContext.tryUse()
if (!ctx) { return }
htmlContext.bodyAppend.unshift(`<script>window.__NUXT_LOGS__ = ${devalue(asyncContext.use().logs)}</script>`)
})
}