Skip to content

Commit

Permalink
fix: avoid warming delayed script src
Browse files Browse the repository at this point in the history
Relates to #295
  • Loading branch information
harlan-zw committed Oct 10, 2024
1 parent ffba718 commit 357d02a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/runtime/composables/useScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type UseScriptContext<T extends Record<symbol | string, any>> =
*/
$script: Promise<T> & VueScriptInstance<T>
}
const ValidPreloadTriggers = ['onNuxtReady', 'client'] as const

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>> {
input = typeof input === 'string' ? { src: input } : input
Expand All @@ -33,7 +34,7 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
nuxtApp.$scripts = nuxtApp.$scripts! || reactive({})
const exists = !!(nuxtApp.$scripts as Record<string, any>)?.[id]
// need to make sure it's not already registered
if (!exists && input.src && options.trigger !== 'server' && (rel === 'preload' || isCrossOrigin)) {
if (!exists && input.src && ValidPreloadTriggers.includes(options.trigger) && (rel === 'preload' || isCrossOrigin)) {

Check failure on line 37 in src/runtime/composables/useScript.ts

View workflow job for this annotation

GitHub Actions / ci

Argument of type 'Ref<boolean, boolean> | Promise<boolean | void> | "client" | "server" | "manual" | ((fn: any) => any) | "onNuxtReady" | null | undefined' is not assignable to parameter of type '"client" | "onNuxtReady"'.
useHead({
link: [
{
Expand Down

0 comments on commit 357d02a

Please sign in to comment.