Skip to content

Commit

Permalink
fix(nuxt): ignore failures to access asyncContext in environments wit…
Browse files Browse the repository at this point in the history
…hout it
  • Loading branch information
danielroe committed Mar 17, 2024
1 parent 0d9c63b commit 523db1a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/nuxt/src/core/runtime/nitro/dev-server-logs.ts
Expand Up @@ -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>`)
})
}
Expand Down

0 comments on commit 523db1a

Please sign in to comment.