fix(nuxt): guard window access more carefully

This commit is contained in:
Daniel Roe 2024-03-15 19:51:35 -07:00
parent 1dc51668a4
commit 977377777a
No known key found for this signature in database
GPG Key ID: CBC814C393D93268

View File

@ -7,6 +7,8 @@ import { defineNuxtPlugin } from '../nuxt'
import { devLogs, devRootDir } from '#build/nuxt.config.mjs'
export default defineNuxtPlugin((nuxtApp) => {
if (!import.meta.client || import.meta.test) { return }
// Show things in console
if (devLogs !== 'silent') {
const logger = createConsola({
@ -41,7 +43,7 @@ export default defineNuxtPlugin((nuxtApp) => {
// pass SSR logs after hydration
nuxtApp.hooks.hook('app:suspense:resolve', async () => {
if (window && window.__NUXT_LOGS__) {
if (typeof window !== 'undefined' && window.__NUXT_LOGS__) {
await nuxtApp.hooks.callHook('dev:ssr-logs', window.__NUXT_LOGS__)
}
})