fix(nuxt): prevent fallthrough attributes on custom NuxtLink (#19379)

This commit is contained in:
Lucie 2023-03-02 10:53:46 +01:00 committed by GitHub
parent d4a75240ac
commit 0be8cda77a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 12 deletions

View File

@ -211,20 +211,29 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
return () => { return () => {
if (!isExternal.value) { if (!isExternal.value) {
// Internal link const routerLinkProps: Record<string, any> = {
return h(
resolveComponent('RouterLink'),
{
ref: process.server ? undefined : (ref: any) => { el!.value = ref?.$el }, ref: process.server ? undefined : (ref: any) => { el!.value = ref?.$el },
to: to.value, to: to.value,
...((prefetched.value && !props.custom) ? { class: props.prefetchedClass || options.prefetchedClass } : {}),
activeClass: props.activeClass || options.activeClass, activeClass: props.activeClass || options.activeClass,
exactActiveClass: props.exactActiveClass || options.exactActiveClass, exactActiveClass: props.exactActiveClass || options.exactActiveClass,
replace: props.replace, replace: props.replace,
ariaCurrentValue: props.ariaCurrentValue, ariaCurrentValue: props.ariaCurrentValue,
custom: props.custom, custom: props.custom
rel: props.rel }
},
// `custom` API cannot support fallthrough attributes as the slot
// may render fragment or text root nodes (#14897, #19375)
if (!props.custom) {
if (prefetched.value) {
routerLinkProps.class = props.prefetchedClass || options.prefetchedClass
}
routerLinkProps.rel = props.rel
}
// Internal link
return h(
resolveComponent('RouterLink'),
routerLinkProps,
slots.default slots.default
) )
} }

View File

@ -40,7 +40,7 @@ describe.skipIf(isWindows)('minimal nuxt application', () => {
it('default server bundle size', async () => { it('default server bundle size', async () => {
stats.server = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir) stats.server = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir)
expect(stats.server.totalBytes).toBeLessThan(92900) expect(stats.server.totalBytes).toBeLessThan(93000)
const modules = await analyzeSizes('node_modules/**/*', serverDir) const modules = await analyzeSizes('node_modules/**/*', serverDir)
expect(modules.totalBytes).toBeLessThan(2722000) expect(modules.totalBytes).toBeLessThan(2722000)