Skip to content

Commit

Permalink
fix(nuxt): handle errors parsing/stringifying logs
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Mar 27, 2024
1 parent fa9d437 commit 4a87c35
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/nuxt/src/app/plugins/dev-server-logs.ts
Expand Up @@ -37,7 +37,11 @@ export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.hook('dev:ssr-logs', (logs) => {
for (const log of logs) {
// deduplicate so we don't print out things that are logged on client
if (!hydrationLogs.size || !hydrationLogs.has(JSON.stringify(log.args))) {
try {
if (!hydrationLogs.size || !hydrationLogs.has(JSON.stringify(log.args))) {
logger.log(normalizeServerLog({ ...log }))
}
} catch {
logger.log(normalizeServerLog({ ...log }))
}
}
Expand All @@ -50,7 +54,8 @@ export default defineNuxtPlugin((nuxtApp) => {
// pass SSR logs after hydration
nuxtApp.hooks.hook('app:suspense:resolve', async () => {
if (typeof window !== 'undefined') {
const logs = parse(document.getElementById('__NUXT_LOGS__')?.textContent || '[]', nuxtApp._payloadRevivers) as LogObject[]
const content = document.getElementById('__NUXT_LOGS__')?.textContent
const logs = content ? parse(content, nuxtApp._payloadRevivers) as LogObject[] : []
await nuxtApp.hooks.callHook('dev:ssr-logs', logs)
}
})
Expand Down

0 comments on commit 4a87c35

Please sign in to comment.