feat: non-POJO check in rendered hook (#5137)

* feat: non-POJO check in rendered hook

Signed-off-by: Calum H. <contact@cal.engineer>

* fix: lint

* move to plugin

---------

Signed-off-by: Calum H. <contact@cal.engineer>
This commit is contained in:
Calum H.
2026-01-16 19:56:46 +00:00
committed by GitHub
parent 82e4eb7b40
commit 72458f5c41

View File

@@ -0,0 +1,24 @@
import { defineNuxtPlugin } from '#imports'
export default defineNuxtPlugin((nuxt) => {
if (import.meta.server) {
nuxt.hooks.hook('app:rendered', (ctx) => {
if (ctx.ssrContext?.payload?.data) {
const check = (obj: any, path = 'payload') => {
if (!obj || typeof obj !== 'object') return
if (
obj.constructor &&
obj.constructor.name !== 'Object' &&
obj.constructor.name !== 'Array'
) {
console.error(`Non-POJO at ${path}:`, obj.constructor.name)
}
for (const [k, v] of Object.entries(obj)) {
check(v, `${path}.${k}`)
}
}
check(ctx.ssrContext.payload.data)
}
})
}
})