fix(vue): clone slots before passing to icon (#4339)

Co-authored-by: Axtho <th@ebtc.org>
This commit is contained in:
Thomas Hochstetter
2026-05-01 14:52:32 +02:00
committed by GitHub
parent 6d38f90429
commit 446e644e63
2 changed files with 21 additions and 1 deletions

View File

@@ -19,7 +19,7 @@ const createLucideIcon =
iconNode,
name: iconName,
},
slots,
slots.default ? { default: slots.default } : undefined,
);
export default createLucideIcon;

View File

@@ -1,6 +1,7 @@
import { describe, it, expect, vi, afterEach } from 'vitest';
import { render, fireEvent, cleanup } from '@testing-library/vue';
import { Smile, Edit2, Pen } from '../src/lucide-vue';
import createLucideIcon from '../src/createLucideIcon';
import defaultAttributes from '../src/defaultAttributes';
describe('Using lucide icon components', () => {
@@ -108,6 +109,25 @@ describe('Using lucide icon components', () => {
expect(container).toMatchSnapshot();
});
it('should handle non-extensible slots objects', () => {
const Icon = createLucideIcon('test-icon', [['path', { d: 'M0 0h1', key: 'test-key' }]]);
const slots = Object.freeze({
default: () => 'Hello World',
});
expect(() =>
Icon(
{},
{
attrs: {},
emit: vi.fn(),
expose: vi.fn(),
slots,
},
),
).not.toThrow();
});
it('should render the alias icon', () => {
const { container } = render(Pen, {
props: {