Skip to content

Commit 8730bb9

Browse files
committed
fix(scripts): beforeInit hook for script deps
1 parent c0510f4 commit 8730bb9

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

packages/schema/src/script.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,9 @@ export interface UseScriptOptions<T> extends HeadEntryOptions {
4141
* calling the event, allowing the event to be reactive.
4242
*/
4343
eventContext?: any
44+
/**
45+
* Called before the script is initialized. Will not be triggered when the script is already loaded. This means
46+
* this is guaranteed to be called only once, unless the script is removed and re-added.
47+
*/
48+
beforeInit?: () => void
4449
}

packages/unhead/src/composables/useScript.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export function useScript<T>(_input: UseScriptInput, _options?: UseScriptOptions
6767
},
6868
load() {
6969
if (!script.entry) {
70+
options.beforeInit?.()
7071
syncStatus('loading')
7172
const defaults: Required<Head>['script'][0] = {
7273
defer: true,

0 commit comments

Comments
 (0)