Skip to content

Commit fa2778a

Browse files
committed
fix(ssr): serialize non enumerable id
Fix #1398
1 parent 7a55685 commit fa2778a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

packages/nuxt/src/runtime/payload-plugin.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,25 @@ export default definePayloadPlugin(() => {
2929

3030
return parsed
3131
})
32+
// to handle the `id` non-enumerable property
33+
definePayloadReducer(
34+
'DocumentData',
35+
(data: any) =>
36+
data &&
37+
typeof data === 'object' &&
38+
'id' in data &&
39+
JSON.stringify({
40+
id: data.id,
41+
...data,
42+
})
43+
)
44+
definePayloadReviver('DocumentData', (data: string) => {
45+
const parsed = JSON.parse(data)
46+
// preserve the non-enumerable property
47+
// we need to delete it first
48+
delete parsed.id
49+
return Object.defineProperty(parsed, 'id', {
50+
value: parsed.id,
51+
})
52+
})
3253
})

0 commit comments

Comments
 (0)