mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-18 09:25:54 +00:00
fix(nuxt): avoid invoking shouldPrefetch
on the server side (#30591)
This commit is contained in:
parent
07146ddf48
commit
68ea5c7d85
@ -325,10 +325,13 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
|
||||
const elRef = import.meta.server ? undefined : (ref: any) => { el!.value = props.custom ? ref?.$el?.nextElementSibling : ref?.$el }
|
||||
|
||||
function shouldPrefetch (mode: 'visibility' | 'interaction') {
|
||||
if (import.meta.server) { return }
|
||||
return !prefetched.value && (typeof props.prefetchOn === 'string' ? props.prefetchOn === mode : (props.prefetchOn?.[mode] ?? options.prefetchOn?.[mode])) && (props.prefetch ?? options.prefetch) !== false && props.noPrefetch !== true && props.target !== '_blank' && !isSlowConnection()
|
||||
}
|
||||
|
||||
async function prefetch (nuxtApp = useNuxtApp()) {
|
||||
if (import.meta.server) { return }
|
||||
|
||||
if (prefetched.value) { return }
|
||||
|
||||
prefetched.value = true
|
||||
@ -395,12 +398,14 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
|
||||
// `custom` API cannot support fallthrough attributes as the slot
|
||||
// may render fragment or text root nodes (#14897, #19375)
|
||||
if (!props.custom) {
|
||||
if (shouldPrefetch('interaction')) {
|
||||
routerLinkProps.onPointerenter = prefetch.bind(null, undefined)
|
||||
routerLinkProps.onFocus = prefetch.bind(null, undefined)
|
||||
}
|
||||
if (prefetched.value) {
|
||||
routerLinkProps.class = props.prefetchedClass || options.prefetchedClass
|
||||
if (import.meta.client) {
|
||||
if (shouldPrefetch('interaction')) {
|
||||
routerLinkProps.onPointerenter = prefetch.bind(null, undefined)
|
||||
routerLinkProps.onFocus = prefetch.bind(null, undefined)
|
||||
}
|
||||
if (prefetched.value) {
|
||||
routerLinkProps.class = props.prefetchedClass || options.prefetchedClass
|
||||
}
|
||||
}
|
||||
routerLinkProps.rel = props.rel || undefined
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user