Skip to content

Commit

Permalink
fix(scripts): lazily trigger beforeInit
Browse files Browse the repository at this point in the history
Fixes #351
  • Loading branch information
harlan-zw committed May 22, 2024
1 parent 62509f6 commit d1e1930
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/unhead/src/composables/useScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export function useScript<T extends Record<symbol | string, any>>(_input: UseScr
const id = input.key || hashCode(input.src || (typeof input.innerHTML === 'string' ? input.innerHTML : ''))
if (head._scripts?.[id])
return head._scripts[id]
options.beforeInit?.()
const syncStatus = (s: ScriptInstance<T>['status']) => {
script.status = s
head.hooks.callHook(`script:updated`, hookCtx)
Expand Down Expand Up @@ -84,6 +83,7 @@ export function useScript<T extends Record<symbol | string, any>>(_input: UseScr
defaults.crossorigin = 'anonymous'
defaults.referrerpolicy = 'no-referrer'
}
options.beforeInit?.()
// status should get updated from script events
script.entry = head.push({
script: [{ ...defaults, ...input, key: `script.${id}` }],
Expand Down

0 comments on commit d1e1930

Please sign in to comment.