@@ -171,7 +171,7 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
171171 throw new Error ( 'useScript with partytown requires a src' )
172172 }
173173 useHead ( {
174- script : [ { src, type : 'text/partytown' } ] ,
174+ script : [ { src, type : 'text/partytown' as 'text/javascript' } ] ,
175175 } )
176176 const nuxtApp = useNuxtApp ( ) as NuxtScriptsApp
177177 ensureScripts ( nuxtApp )
@@ -238,10 +238,11 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
238238 // browser hint optimizations
239239 const nuxtApp = useNuxtApp ( ) as NuxtScriptsApp
240240 const id = String ( resolveScriptKey ( input ) )
241- options . head = options . head || injectHead ( )
241+ options . head = options . head || injectHead ( ) as NonNullable < typeof options . head >
242242 if ( ! options . head ) {
243243 throw new Error ( 'useScript() has been called without Nuxt context.' )
244244 }
245+ const headHooks = options . head . hooks !
245246 ensureScripts ( nuxtApp )
246247 const exists = ! ! ( nuxtApp . $scripts as Record < string , any > ) ?. [ id ]
247248
@@ -318,7 +319,7 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
318319 ...ctx ,
319320 trigger : typeof trigger === 'object' ? ( trigger instanceof Promise ? 'promise' : JSON . stringify ( trigger ) ) : trigger ,
320321 } )
321- options . head . hooks . hook ( 'script:updated' , ( entry ) => {
322+ headHooks . hook ( 'script:updated' , ( entry ) => {
322323 if ( entry . script . id !== instance . id )
323324 return
324325 const status = entry . script . status
@@ -369,7 +370,7 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
369370 }
370371
371372 if ( ! nuxtApp . _scripts [ instance . id ] ) {
372- options . head . hooks . hook ( 'script:updated' , ( ctx ) => {
373+ headHooks . hook ( 'script:updated' , ( ctx ) => {
373374 if ( ctx . script . id !== instance . id )
374375 return
375376 // convert the status to a timestamp
@@ -382,7 +383,7 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
382383 syncScripts ( )
383384 } )
384385 // @ts -expect-error untyped
385- options . head . hooks . hook ( 'script:instance-fn' , ( ctx ) => {
386+ headHooks . hook ( 'script:instance-fn' , ( ctx ) => {
386387 if ( ctx . script . id !== instance . id || String ( ctx . fn ) . startsWith ( '__v_' ) )
387388 return
388389 // log all events
0 commit comments