You've already forked AstralRinth
forked from didirus/AstralRinth
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:
24
apps/frontend/src/plugins/debug-pojo.ts
Normal file
24
apps/frontend/src/plugins/debug-pojo.ts
Normal 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)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user