Skip to content

Commit

Permalink
fix(scripts): still resolve load promise when no use() is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed May 7, 2024
1 parent a121cb0 commit e23010f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/unhead/src/composables/useScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@ export function useScript<T extends Record<symbol | string, any>>(_input: UseScr
const _ = head.hooks.hook('script:updated', ({ script }) => {
if (script.id === id && (script.status === 'loaded' || script.status === 'error')) {
if (script.status === 'loaded') {
const api = options.use?.()
api && resolve(api)
if (typeof options.use === 'function') {
const api = options.use()
api && resolve(api)
}
// scripts without any use() function
else {
resolve({} as T)
}
}
else if (script.status === 'error') {
reject(new Error(`Failed to load script: ${input.src}`))
Expand Down

0 comments on commit e23010f

Please sign in to comment.