Skip to content

Commit 357d02a

Browse files
committed
fix: avoid warming delayed script src
Relates to #295
1 parent ffba718 commit 357d02a

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/runtime/composables/useScript.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export type UseScriptContext<T extends Record<symbol | string, any>> =
2121
*/
2222
$script: Promise<T> & VueScriptInstance<T>
2323
}
24+
const ValidPreloadTriggers = ['onNuxtReady', 'client'] as const
2425

2526
export function useScript<T extends Record<symbol | string, any> = Record<symbol | string, any>, U = Record<symbol | string, any>>(input: UseScriptInput, options?: NuxtUseScriptOptions<T, U>): UseScriptContext<UseFunctionType<NuxtUseScriptOptions<T, U>, T>> {
2627
input = typeof input === 'string' ? { src: input } : input
@@ -33,7 +34,7 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
3334
nuxtApp.$scripts = nuxtApp.$scripts! || reactive({})
3435
const exists = !!(nuxtApp.$scripts as Record<string, any>)?.[id]
3536
// need to make sure it's not already registered
36-
if (!exists && input.src && options.trigger !== 'server' && (rel === 'preload' || isCrossOrigin)) {
37+
if (!exists && input.src && ValidPreloadTriggers.includes(options.trigger) && (rel === 'preload' || isCrossOrigin)) {
3738
useHead({
3839
link: [
3940
{

0 commit comments

Comments
 (0)