Skip to content

Commit 9890124

Browse files
committed
fix: allow useScript to re-register trigger
Relates to #212
1 parent 83d6d18 commit 9890124

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/runtime/composables/useScript.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,10 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
3131
const nuxtApp = useNuxtApp()
3232
const id = resolveScriptKey(input) as keyof typeof nuxtApp._scripts
3333
nuxtApp.$scripts = nuxtApp.$scripts! || reactive({})
34-
// return early
35-
if ((nuxtApp.$scripts as Record<string, any>)[id]) {
36-
return (nuxtApp.$scripts as Record<string, any>)[id]
37-
}
34+
const exists = !!(nuxtApp.$scripts as Record<string, any>)?.[id]
3835
if (import.meta.client) {
3936
// only validate if we're initializing the script
40-
if (!nuxtApp._scripts?.[id]) {
37+
if (!exists) {
4138
performance?.mark?.('mark_feature_usage', {
4239
detail: {
4340
feature: options.performanceMarkFeature ?? `nuxt-scripts:${id}`,
@@ -50,6 +47,9 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
5047
nuxtApp.$scripts[id] = instance
5148
// used for devtools integration
5249
if (import.meta.dev && import.meta.client) {
50+
if (exists) {
51+
return instance as any as UseScriptContext<UseFunctionType<NuxtUseScriptOptions<T, U>, T>>
52+
}
5353
// sync scripts to nuxtApp with debug details
5454
const payload: NuxtDevToolsScriptInstance = {
5555
...options.devtools,

0 commit comments

Comments
 (0)