mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(nuxt): observe slot element in custom nuxt-link (#19802)
This commit is contained in:
parent
4f683319cb
commit
3a971d0b36
@ -198,13 +198,15 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
|
||||
// Prefetching
|
||||
const prefetched = ref(false)
|
||||
const el = process.server ? undefined : ref<HTMLElement | null>(null)
|
||||
const elRef = process.server ? undefined : (ref: any) => { el!.value = props.custom ? ref?.$el?.nextElementSibling : ref?.$el }
|
||||
|
||||
if (process.client) {
|
||||
checkPropConflicts(props, 'prefetch', 'noPrefetch')
|
||||
const shouldPrefetch = props.prefetch !== false && props.noPrefetch !== true && props.target !== '_blank' && !isSlowConnection()
|
||||
if (shouldPrefetch) {
|
||||
const nuxtApp = useNuxtApp()
|
||||
let idleId: number
|
||||
let unobserve: (() => void)| null = null
|
||||
let unobserve: (() => void) | null = null
|
||||
onMounted(() => {
|
||||
const observer = useObserver()
|
||||
onNuxtReady(() => {
|
||||
@ -236,7 +238,7 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
|
||||
return () => {
|
||||
if (!isExternal.value) {
|
||||
const routerLinkProps: Record<string, any> = {
|
||||
ref: process.server ? undefined : (ref: any) => { el!.value = ref?.$el },
|
||||
ref: elRef,
|
||||
to: to.value,
|
||||
activeClass: props.activeClass || options.activeClass,
|
||||
exactActiveClass: props.exactActiveClass || options.exactActiveClass,
|
||||
|
@ -26,7 +26,7 @@ describe.skipIf(isWindows)('minimal nuxt application', () => {
|
||||
|
||||
it('default client bundle size', async () => {
|
||||
stats.client = await analyzeSizes('**/*.js', publicDir)
|
||||
expect(stats.client.totalBytes).toBeLessThan(106600)
|
||||
expect(stats.client.totalBytes).toBeLessThan(106650)
|
||||
expect(stats.client.files.map(f => f.replace(/\..*\.js/, '.js'))).toMatchInlineSnapshot(`
|
||||
[
|
||||
"_nuxt/_plugin-vue_export-helper.js",
|
||||
|
Loading…
Reference in New Issue
Block a user