Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4a87c35

Browse files
committed
fix(nuxt): handle errors parsing/stringifying logs
1 parent fa9d437 commit 4a87c35

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/nuxt/src/app/plugins/dev-server-logs.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ export default defineNuxtPlugin((nuxtApp) => {
3737
nuxtApp.hook('dev:ssr-logs', (logs) => {
3838
for (const log of logs) {
3939
// deduplicate so we don't print out things that are logged on client
40-
if (!hydrationLogs.size || !hydrationLogs.has(JSON.stringify(log.args))) {
40+
try {
41+
if (!hydrationLogs.size || !hydrationLogs.has(JSON.stringify(log.args))) {
42+
logger.log(normalizeServerLog({ ...log }))
43+
}
44+
} catch {
4145
logger.log(normalizeServerLog({ ...log }))
4246
}
4347
}
@@ -50,7 +54,8 @@ export default defineNuxtPlugin((nuxtApp) => {
5054
// pass SSR logs after hydration
5155
nuxtApp.hooks.hook('app:suspense:resolve', async () => {
5256
if (typeof window !== 'undefined') {
53-
const logs = parse(document.getElementById('__NUXT_LOGS__')?.textContent || '[]', nuxtApp._payloadRevivers) as LogObject[]
57+
const content = document.getElementById('__NUXT_LOGS__')?.textContent
58+
const logs = content ? parse(content, nuxtApp._payloadRevivers) as LogObject[] : []
5459
await nuxtApp.hooks.callHook('dev:ssr-logs', logs)
5560
}
5661
})

0 commit comments

Comments
 (0)