From 8c42722034e614ab43860083c4700f378d566e1c Mon Sep 17 00:00:00 2001 From: harlan Date: Thu, 14 Mar 2024 11:13:20 +1100 Subject: [PATCH] fix(scripts): ensure script is synced to deduper --- packages/unhead/src/composables/useScript.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/unhead/src/composables/useScript.ts b/packages/unhead/src/composables/useScript.ts index f50f217d..baafd8f2 100644 --- a/packages/unhead/src/composables/useScript.ts +++ b/packages/unhead/src/composables/useScript.ts @@ -9,6 +9,7 @@ import type { UseScriptOptions, UseScriptResolvedInput, } from '@unhead/schema' +import { defu } from 'defu' import { getActiveHead } from './useActiveHead' const UseScriptDefaults: Script = { @@ -113,6 +114,9 @@ export function useScript(_input: UseScriptInput, _options?: UseScriptOptions transform, head, }) + head._scripts = defu(head._scripts, { + [id]: script, + }) return script.waitForLoad() }, } @@ -126,6 +130,9 @@ export function useScript(_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, + }) } })