diff --git a/packages/unhead/src/composables/useScript.ts b/packages/unhead/src/composables/useScript.ts index af2e3ef4..67a1b676 100644 --- a/packages/unhead/src/composables/useScript.ts +++ b/packages/unhead/src/composables/useScript.ts @@ -76,8 +76,7 @@ export function useScript = Record requestAnimationFrame(() => resolve(api)) const _ = head.hooks.hook('script:updated', ({ script }) => { // vue augmentation... not ideal - // @ts-expect-error runtime augmentation - const status = typeof script.status === 'object' ? script.status.value : script.status + const status = script.status if (script.id === id && (status === 'loaded' || status === 'error')) { if (status === 'loaded') { if (typeof options.use === 'function') { diff --git a/packages/vue/src/composables/useScript.ts b/packages/vue/src/composables/useScript.ts index ebb7ec6f..ada7d370 100644 --- a/packages/vue/src/composables/useScript.ts +++ b/packages/vue/src/composables/useScript.ts @@ -61,7 +61,6 @@ export function useScript = Record // Note: we don't remove scripts on unmount as it's not a common use case and reloading the script may be expensive - script.status = status if (scope) { const _registerCb = (key: 'loaded' | 'error', cb: any) => { if (!script._cbs[key]) { @@ -83,5 +82,12 @@ export function useScript = Record void | Promise) => _registerCb('loaded', cb) script.onError = (cb: (err?: Error) => void | Promise) => _registerCb('error', cb) } - return script + return new Proxy(script, { + get(_, key, a) { + // we can't override status as there's a race condition + if (key === 'status') + return status + return Reflect.get(_, key, a) + }, + }) }