diff --git a/src/runtime/components/Button.vue b/src/runtime/components/Button.vue index c1aad4c31b..18cb50c7f5 100644 --- a/src/runtime/components/Button.vue +++ b/src/runtime/components/Button.vue @@ -59,6 +59,8 @@ import UAvatar from './Avatar.vue' import ULink from './Link.vue' import ULinkBase from './LinkBase.vue' +defineOptions({ inheritAttrs: false }) + const props = defineProps() const slots = defineSlots() @@ -66,6 +68,7 @@ const appConfig = useAppConfig() as Button['AppConfig'] const uiProp = useComponentUI('button', props) const { orientation, size: buttonSize } = useFieldGroup(props) +const isLink = computed(() => !!(props.to || props.href)) const linkProps = useForwardProps(pickLinkProps(props)) const loadingAutoState = ref(false) @@ -118,10 +121,11 @@ const ui = computed(() => tv({ diff --git a/test/components/Button.bench.ts b/test/components/Button.bench.ts new file mode 100644 index 0000000000..e68cdad142 --- /dev/null +++ b/test/components/Button.bench.ts @@ -0,0 +1,33 @@ +import { defineComponent, h } from 'vue' +import { describe, bench } from 'vitest' +import { mountSuspended } from '@nuxt/test-utils/runtime' +import Button from '../../src/runtime/components/Button.vue' + +const BUTTON_COUNT = 500 + +function createButtonList(props: Record) { + return defineComponent({ + setup() { + return () => h('div', Array.from({ length: BUTTON_COUNT }, (_, i) => + h(Button, { key: i, label: `Button ${i}`, ...props }) + )) + } + }) +} + +describe('Button mount performance', () => { + bench(`${BUTTON_COUNT} plain buttons`, async () => { + const wrapper = await mountSuspended(createButtonList({})) + wrapper.unmount() + }) + + bench(`${BUTTON_COUNT} link buttons`, async () => { + const wrapper = await mountSuspended(createButtonList({ to: '/test' })) + wrapper.unmount() + }) + + bench(`${BUTTON_COUNT} plain buttons with icon`, async () => { + const wrapper = await mountSuspended(createButtonList({ icon: 'i-lucide-rocket' })) + wrapper.unmount() + }) +})