mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 23:32:38 +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 }
|
const elRef = import.meta.server ? undefined : (ref: any) => { el!.value = props.custom ? ref?.$el?.nextElementSibling : ref?.$el }
|
||||||
|
|
||||||
function shouldPrefetch (mode: 'visibility' | 'interaction') {
|
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()
|
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()) {
|
async function prefetch (nuxtApp = useNuxtApp()) {
|
||||||
|
if (import.meta.server) { return }
|
||||||
|
|
||||||
if (prefetched.value) { return }
|
if (prefetched.value) { return }
|
||||||
|
|
||||||
prefetched.value = true
|
prefetched.value = true
|
||||||
@ -395,6 +398,7 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
|
|||||||
// `custom` API cannot support fallthrough attributes as the slot
|
// `custom` API cannot support fallthrough attributes as the slot
|
||||||
// may render fragment or text root nodes (#14897, #19375)
|
// may render fragment or text root nodes (#14897, #19375)
|
||||||
if (!props.custom) {
|
if (!props.custom) {
|
||||||
|
if (import.meta.client) {
|
||||||
if (shouldPrefetch('interaction')) {
|
if (shouldPrefetch('interaction')) {
|
||||||
routerLinkProps.onPointerenter = prefetch.bind(null, undefined)
|
routerLinkProps.onPointerenter = prefetch.bind(null, undefined)
|
||||||
routerLinkProps.onFocus = prefetch.bind(null, undefined)
|
routerLinkProps.onFocus = prefetch.bind(null, undefined)
|
||||||
@ -402,6 +406,7 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
|
|||||||
if (prefetched.value) {
|
if (prefetched.value) {
|
||||||
routerLinkProps.class = props.prefetchedClass || options.prefetchedClass
|
routerLinkProps.class = props.prefetchedClass || options.prefetchedClass
|
||||||
}
|
}
|
||||||
|
}
|
||||||
routerLinkProps.rel = props.rel || undefined
|
routerLinkProps.rel = props.rel || undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user