Skip to content

Commit

Permalink
fix(scripts): ensure script is synced to deduper
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Mar 14, 2024
1 parent 947154e commit 8c42722
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/unhead/src/composables/useScript.ts
Expand Up @@ -9,6 +9,7 @@ import type {
UseScriptOptions,
UseScriptResolvedInput,
} from '@unhead/schema'
import { defu } from 'defu'
import { getActiveHead } from './useActiveHead'

const UseScriptDefaults: Script = {
Expand Down Expand Up @@ -113,6 +114,9 @@ export function useScript<T>(_input: UseScriptInput, _options?: UseScriptOptions
transform,
head,
})
head._scripts = defu(head._scripts, {
[id]: script,
})
return script.waitForLoad()
},
}
Expand All @@ -126,6 +130,9 @@ export function useScript<T>(_input: UseScriptInput, _options?: UseScriptOptions
script.status = fn === 'onload' ? 'loaded' : fn === 'onerror' ? 'error' : 'loading'
head.hooks.callHook(`script:updated`, hookCtx)
_fn && _fn(e)
head._scripts = defu(head._scripts, {
[id]: script,
})
}
})

Expand Down

0 comments on commit 8c42722

Please sign in to comment.