Skip to content

Commit df8c4f7

Browse files
committed
fix(kit): add default values for destructured references in addTypeTemplate hooks
Fixes issue where nodeReferences, sharedReferences, and references arrays could be undefined when destructured in prepare:types and nitro:prepare:types hooks, causing 'Cannot read properties of undefined (reading "push")' errors. This ensures backward compatibility by providing empty arrays as defaults when the hook payload doesn't contain these properties.
1 parent 0b1129e commit df8c4f7

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

packages/kit/src/template.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,18 @@ export function addTypeTemplate<T> (_template: NuxtTypeTemplate<T>, context?: {
8080

8181
// Add template to types reference
8282
if (!context || context.nuxt) {
83-
nuxt.hook('prepare:types', ({ references }) => {
84-
references.push({ path: template.dst })
83+
nuxt.hook('prepare:types', (payload) => {
84+
(payload.references ||= []).push({ path: template.dst })
8585
})
8686
}
8787
if (context?.node) {
88-
nuxt.hook('prepare:types', ({ nodeReferences }) => {
89-
nodeReferences.push({ path: template.dst })
88+
nuxt.hook('prepare:types', (payload) => {
89+
(payload.nodeReferences ||= []).push({ path: template.dst })
9090
})
9191
}
9292
if (context?.shared) {
93-
nuxt.hook('prepare:types', ({ sharedReferences }) => {
94-
sharedReferences.push({ path: template.dst })
93+
nuxt.hook('prepare:types', (payload) => {
94+
(payload.sharedReferences ||= []).push({ path: template.dst })
9595
})
9696
}
9797

@@ -105,8 +105,8 @@ export function addTypeTemplate<T> (_template: NuxtTypeTemplate<T>, context?: {
105105
}
106106

107107
if (context?.nitro) {
108-
nuxt.hook('nitro:prepare:types', ({ references }) => {
109-
references.push({ path: template.dst })
108+
nuxt.hook('nitro:prepare:types', (payload) => {
109+
(payload.references ||= []).push({ path: template.dst })
110110
})
111111
}
112112

0 commit comments

Comments
 (0)