Skip to content

Commit

Permalink
fix: useScript missing script API's return in proxy (#302)
Browse files Browse the repository at this point in the history
* fix: useScript missing script API's return in proxy

* fix: set the loaded field to true when the status is loaded

---------

Co-authored-by: Chuankai Wei <chuankai.wei@lotusflare.com>
  • Loading branch information
wckgo and chuankaiwei authored Jan 15, 2024
1 parent 4db8d1f commit c42c57d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/unhead/src/composables/useScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export function useScript<T>(input: UseScriptInput, _options?: UseScriptOptions<
resolve(options.use())
function watchForScriptLoaded({ script }: { script: ScriptInstance<T> }) {
if (script.id === id && script.status === 'loaded') {
script.loaded = true
resolve(options.use?.() as T)
head!.hooks.removeHook('script:updated', watchForScriptLoaded)
}
Expand Down Expand Up @@ -172,7 +173,7 @@ export function useScript<T>(input: UseScriptInput, _options?: UseScriptOptions<
return script.waitForLoad().then(
(api) => {
// @ts-expect-error untyped
api[fn](...args)
return api[fn](...args)
},
)
}
Expand Down

0 comments on commit c42c57d

Please sign in to comment.