fix(deps): keep Lucide SVG markup and Undici tests compatible

Build standalone SVG icons without a React context. Use accessible actions in tests and give the mocked dispatchers the interface the adapter expects.
This commit is contained in:
Maurice
2026-12-01 13:44:02 +01:00
parent 7f4ece2e6f
commit b77c246df4
15 changed files with 107 additions and 40 deletions
@@ -6,7 +6,6 @@ import {
Globe, History, Puzzle, Bot, Loader2,
} from 'lucide-react'
import PluginIcon from '../shared/PluginIcon'
import { Github } from '../shared/legacyLucideIcons'
import { useInstanceSettings } from './useInstanceSettings'
import { type RangeWarning } from './useRangeBypass'
import { deriveCaps } from './pluginCaps'
@@ -790,7 +789,7 @@ function PluginDetailModal({ item, installed, busy, onInstall, onClose, t, local
footer={(
<DialogFooter>
<Tooltip label={t('admin.plugins.sourceRepo')}>
<a href={repoUrl} target="_blank" rel="noreferrer" aria-label={t('admin.plugins.sourceRepo')} className={linkClass}><Github size={15} /></a>
<a href={repoUrl} target="_blank" rel="noreferrer" aria-label={t('admin.plugins.sourceRepo')} className={linkClass}><PluginIcon name="Github" size={15} /></a>
</Tooltip>
<Tooltip label={t('admin.plugins.reportIssue')}>
<a href={`${repoUrl}/issues`} target="_blank" rel="noreferrer" aria-label={t('admin.plugins.reportIssue')} className={linkClass}><CircleDot size={15} /></a>
@@ -210,11 +210,8 @@ describe('BackupPanel', () => {
await waitFor(() => {
expect(screen.getByText('backup-2025-01-15.zip')).toBeInTheDocument()
})
const trashBtn = Array.from(document.querySelectorAll('button')).find(
b => b.querySelector('svg.lucide-trash2'),
) as HTMLElement
expect(trashBtn).toBeTruthy()
await user.click(trashBtn!)
const trashBtn = screen.getByRole('button', { name: 'Delete' })
await user.click(trashBtn)
// The question is the shared confirm dialog now, not window.confirm
expect(await screen.findByText('Delete backup "backup-2025-01-15.zip"?')).toBeInTheDocument()
const deleteButtons = screen.getAllByRole('button', { name: 'Delete' })
@@ -428,9 +425,7 @@ describe('BackupPanel', () => {
render(<><ToastContainer /><BackupPanel /></>)
await screen.findByText('backup-2025-01-15.zip')
const trashBtn = Array.from(document.querySelectorAll('button')).find(
b => b.querySelector('svg.lucide-trash2'),
) as HTMLElement
const trashBtn = screen.getByRole('button', { name: 'Delete' })
await user.click(trashBtn)
await user.click(await screen.findByRole('button', { name: 'Cancel' }))
expect(deleteCalls).toBe(0)
@@ -113,9 +113,9 @@ describe('MobileEntryView', () => {
const order: string[] = []
const onClose = vi.fn(() => { order.push('close') })
const onDelete = vi.fn(() => { order.push('delete') })
const { container } = renderView(buildEntry(), { onClose, onDelete })
renderView(buildEntry(), { onClose, onDelete })
fireEvent.click(container.querySelector('svg.lucide-trash2')!.closest('button')!)
fireEvent.click(screen.getByRole('button', { name: /Delete/ }))
expect(order).toEqual(['close', 'delete'])
})
@@ -123,7 +123,7 @@ describe('MobileEntryView', () => {
it('FE-COMP-JENTRYVIEW-006: read-only journeys hide the edit and delete actions', () => {
const { container } = renderView(buildEntry(), { readOnly: true })
expect(screen.queryByRole('button', { name: /Edit/ })).not.toBeInTheDocument()
expect(container.querySelector('svg.lucide-trash2')).toBeNull()
expect(screen.queryByRole('button', { name: /Delete/ })).not.toBeInTheDocument()
// the close button stays
expect(container.querySelector('svg.lucide-x')).not.toBeNull()
})
@@ -104,6 +104,7 @@ export default function MobileEntryView({ entry, readOnly, publicPhotoUrl, onClo
</button>
<button type="button"
onClick={() => { onClose(); onDelete(); }}
aria-label={t('common.delete')}
className="w-8 h-8 rounded-lg flex items-center justify-center text-zinc-400 hover:bg-red-50 hover:text-red-500 dark:hover:bg-red-900/20 dark:hover:text-red-400 transition-colors"
>
<Trash2 size={15} />
@@ -15,7 +15,7 @@ import {
Zap,
} from 'lucide-react';
import React from 'react';
import { findLucideIcon } from '../shared/PluginIcon';
import { lucideIconByName } from '../shared/lucideIconLookup';
import './releaseNoticeVisuals.css';
/*
@@ -233,7 +233,7 @@ const VISUALS: Record<string, () => React.ReactElement> = {
export function ReleaseFeatureVisual({ visual, iconName }: { visual?: string; iconName: string }) {
const Drawing = visual ? VISUALS[visual] : undefined;
if (Drawing) return <Drawing />;
const Icon = findLucideIcon(iconName) ?? Sparkles;
const Icon = lucideIconByName[iconName] ?? Sparkles;
return (
<div className="rn-vis rn-vis-icon">
<Icon size={30} strokeWidth={1.6} aria-hidden="true" />
@@ -10,7 +10,7 @@ import { useTranslation, isRtlLanguage } from '../../i18n/index.js';
import { runNoticeAction } from './noticeActions.js';
import { ReleaseNoticeModal } from './ReleaseNoticeModal.js';
import { PATREON_PATH } from '../shared/PatreonIcon';
import { findLucideIcon } from '../shared/PluginIcon';
import { lucideIconByName } from '../shared/lucideIconLookup';
import { lockBodyScroll } from '../../utils/bodyScrollLock.js';
const ReactMarkdown = React.lazy(() =>
@@ -101,7 +101,7 @@ function NoticeContent({ notice, title, body, ctaLabel, secondaryCtaLabel, terti
const isLastPage = total <= 1 || currentPage === total - 1;
const DefaultIcon = SEVERITY_ICONS[notice.severity] ?? Info;
const LucideIcon: React.ElementType = findLucideIcon(notice.icon) ?? DefaultIcon;
const LucideIcon: React.ElementType = lucideIconByName[notice.icon ?? ''] ?? DefaultIcon;
// Real brand logo for each support button, detected from the link target.
const primaryBrand = notice.cta?.kind === 'link' ? brandForHref(notice.cta.href) : null;
@@ -230,7 +230,7 @@ function NoticeContent({ notice, title, body, ctaLabel, secondaryCtaLabel, terti
{notice.highlights && notice.highlights.length > 0 && (
<div className="flex flex-wrap justify-center gap-2 mb-4">
{notice.highlights.map((h, i) => {
const HIcon = findLucideIcon(h.iconName);
const HIcon = lucideIconByName[h.iconName ?? ''];
return (
<span
key={i}
+2 -15
View File
@@ -1,19 +1,6 @@
import type { CSSProperties } from 'react'
import * as LucideIcons from 'lucide-react'
import { Blocks, type LucideIcon } from 'lucide-react'
import { legacyLucideIcons } from './legacyLucideIcons'
// Lucide names are PascalCase. Restricting the lookup to that shape keeps a manifest
// from reaching lucide's non-icon exports (`createLucideIcon`, `icons`, `default`,
// `module.exports`), which are all lowercase-initial.
const LUCIDE_ICON_NAME = /^[A-Z][A-Za-z0-9]*$/
export function findLucideIcon(name: string | null | undefined): LucideIcon | undefined {
if (!name || !LUCIDE_ICON_NAME.test(name) || name === 'Icon') return undefined
const icon = (LucideIcons as unknown as Record<string, LucideIcon | undefined>)[name]
if (typeof icon === 'object') return icon
return legacyLucideIcons.get(name.replace(/^Lucide/, '').replace(/Icon$/, ''))
}
import { lucideIconByName } from './lucideIconLookup'
/**
* Resolves a plugin manifest's `icon` (a lucide icon name, e.g. "Stethoscope") to the
@@ -25,7 +12,7 @@ export function findLucideIcon(name: string | null | undefined): LucideIcon | un
* building nav/tab arrays.
*/
export function resolvePluginIcon(name: string | null | undefined): LucideIcon {
return findLucideIcon(name) ?? Blocks
return lucideIconByName[name ?? ''] ?? Blocks
}
/** Renders the lucide icon a plugin declares in its manifest (Blocks if unknown). */
@@ -0,0 +1,20 @@
import type { LucideIcon } from 'lucide-react';
import * as LucideIcons from 'lucide-react';
import { legacyLucideIcons } from './legacyLucideIcons';
const icons = Object.create(null) as Record<string, LucideIcon | undefined>;
for (const [name, component] of Object.entries(LucideIcons)) {
if (/^[A-Z][A-Za-z0-9]*$/.test(name) && name !== 'Icon' && typeof component === 'object' && component !== null) {
icons[name] = component as LucideIcon;
}
}
for (const [name, component] of legacyLucideIcons) {
icons[name] ??= component;
icons[`Lucide${name}`] ??= component;
icons[`${name}Icon`] ??= component;
}
export const lucideIconByName: Readonly<typeof icons> = icons;