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
+1
View File
@@ -101,6 +101,7 @@
"@fontsource/satisfy": "^5.3.0",
"@fontsource/shrikhand": "^5.3.0",
"@fontsource/yellowtail": "^5.3.0",
"@lucide/icons": "1.82.0",
"@maplibre/maplibre-gl-leaflet": "0.1.4",
"@noble/hashes": "^2.4.0",
"@simplewebauthn/browser": "^14.0.0",
@@ -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;
+45 -5
View File
@@ -1,3 +1,5 @@
import { buildLucideIconNode } from '@lucide/icons/build'
import { Icon, type LucideIconData, type LucideIconNode, type LucideProps } from 'lucide-react'
import type { ReactElement, ReactNode } from 'react'
/**
@@ -9,11 +11,9 @@ import type { ReactElement, ReactNode } from 'react'
* renderer, which is the default. For output that is always a single <svg> with
* a flat list of shape children, that is a poor trade.
*
* Deliberately generic over React elements rather than over lucide's icon
* tables: `iconNode` is closed over inside createLucideIcon and not exported, so
* calling the forwardRef render function is what keeps this working across
* lucide upgrades. iconMarkup.parity.test.ts diffs the output against real Fizz
* for every exported icon, so drift fails the suite instead of shipping.
* The outer Lucide component returns its icon data. The inner Icon reads
* React context, so standalone rendering uses Lucide's SVG builder with the
* default icon props. iconMarkup.parity.test.ts checks the result against React.
*
* Byte-compatibility notes, all verified against react-dom 19.2.6:
* - React escapes & " ' < > the same way in attribute values and in text, so
@@ -50,8 +50,17 @@ const ATTRIBUTE_NAMES: Record<string, string> = {
const SKIP_PROPS = new Set(['children', 'key', 'ref', 'dangerouslySetInnerHTML'])
const LUCIDE_REACT_ATTRIBUTES = {
class: 'className',
'stroke-width': 'strokeWidth',
'stroke-linecap': 'strokeLinecap',
'stroke-linejoin': 'strokeLinejoin',
'vector-effect': 'vectorEffect',
}
type ElementProps = Record<string, unknown> & { children?: ReactNode }
type ForwardRefComponent = { $$typeof: symbol; render: (props: ElementProps, ref: null) => ReactNode }
type LucideElementProps = LucideProps & { icon: LucideIconData }
function escape(value: string | number): string {
return String(value)
@@ -74,6 +83,34 @@ function serializeProps(props: ElementProps): string {
return out
}
function serializeLucideNode([tag, attrs, nodes]: LucideIconNode, children?: ReactNode): string {
const content = nodes?.map(node => serializeLucideNode(node)).join('') ?? ''
return `<${tag}${serializeProps(attrs)}>${content}${serialize(children)}</${tag}>`
}
function serializeLucideIcon({
icon,
color = 'currentColor',
size = 24,
width = size,
height = size,
strokeWidth = 2,
absoluteStrokeWidth,
nonScalingStroke,
className,
children,
...attributes
}: LucideElementProps): string {
const hasA11yProp = Boolean(children) || Object.entries(attributes).some(
([name, value]) => value != null && (name.startsWith('aria-') || name === 'role' || name === 'title'),
)
const node = buildLucideIconNode(icon, {
color, width, height, strokeWidth, absoluteStrokeWidth, nonScalingStroke, className,
hasA11yProp, attributes, attributeNames: LUCIDE_REACT_ATTRIBUTES,
})
return serializeLucideNode(node, children)
}
function serialize(node: unknown): string {
if (node === null || node === undefined || typeof node === 'boolean') return ''
if (typeof node === 'string' || typeof node === 'number') return escape(node)
@@ -86,6 +123,9 @@ function serialize(node: unknown): string {
if (typeof type === 'string') {
return `<${type}${serializeProps(props)}>${serialize(props.children)}</${type}>`
}
if (type === Icon && props.icon) {
return serializeLucideIcon(props as LucideElementProps)
}
if (typeof type === 'object' && type !== null && (type as ForwardRefComponent).$$typeof === FORWARD_REF) {
return serialize((type as ForwardRefComponent).render(props, null))
}
+7
View File
@@ -80,6 +80,7 @@
"@fontsource/satisfy": "^5.3.0",
"@fontsource/shrikhand": "^5.3.0",
"@fontsource/yellowtail": "^5.3.0",
"@lucide/icons": "1.82.0",
"@maplibre/maplibre-gl-leaflet": "0.1.4",
"@noble/hashes": "^2.4.0",
"@simplewebauthn/browser": "^14.0.0",
@@ -5710,6 +5711,12 @@
"integrity": "sha512-llBRm4dT4Z89aRsm6u2oEZ8tfwL/2l6BwpZ7JcyieouniDECM5AqNgr/y08zalEIvW3RSK4upYyybDcmjXqAow==",
"license": "MIT"
},
"node_modules/@lucide/icons": {
"version": "1.82.0",
"resolved": "https://registry.npmjs.org/@lucide/icons/-/icons-1.82.0.tgz",
"integrity": "sha512-B/8pcHiIZi88G0wYjnHlsl28QRgH/8kJXsZ63dtySuTJAh+iMDVluzjJPstF34Rvu73Eahj1cec6bFlWQdbd1w==",
"license": "ISC"
},
"node_modules/@lukeed/csprng": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@lukeed/csprng/-/csprng-1.1.0.tgz",
@@ -25,7 +25,14 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
* applied there would hold a hung identity provider open for a quarter of an
* hour on the strength of a model setting.
*/
const { AgentMock } = vi.hoisted(() => ({ AgentMock: vi.fn() }));
const { AgentMock } = vi.hoisted(() => ({
AgentMock: vi.fn(
class {
dispatch = vi.fn();
constructor(_options: Record<string, unknown>) {}
},
),
}));
vi.mock('undici', async (importOriginal) => ({
...(await importOriginal<typeof import('undici')>()),
Agent: AgentMock,
@@ -14,6 +14,7 @@ const built = vi.hoisted(() => ({
vi.mock('undici', async (importOriginal) => ({
...(await importOriginal<typeof import('undici')>()),
Agent: class {
dispatch = vi.fn();
constructor(readonly opts: unknown) {
built.agents.push(opts);
}
@@ -23,6 +24,7 @@ vi.mock('undici', async (importOriginal) => ({
}
},
ProxyAgent: class {
dispatch = vi.fn();
constructor(opts: Record<string, unknown>) {
built.proxies.push(opts);
}
@@ -20,7 +20,14 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
* spread init the lint rule could not see into, waited undici's five minutes
* for a hung host and read whatever size the host sent back into memory.
*/
const { AgentMock } = vi.hoisted(() => ({ AgentMock: vi.fn() }));
const { AgentMock } = vi.hoisted(() => ({
AgentMock: vi.fn(
class {
dispatch = vi.fn();
constructor(_options: Record<string, unknown>) {}
},
),
}));
vi.mock('undici', async (importOriginal) => ({
...(await importOriginal<typeof import('undici')>()),
Agent: AgentMock,
@@ -23,6 +23,7 @@ vi.mock('dns/promises', () => ({
vi.mock('undici', async (importOriginal) => ({
...(await importOriginal<typeof import('undici')>()),
Agent: class MockAgent {
dispatch = vi.fn();
options: any;
constructor(opts: any) {
this.options = opts;