import { useState, useEffect } from 'react'; import { authenticatedFetch } from '../../utils/api'; type Props = { pluginName: string; iconFile: string; className?: string; }; // Module-level cache so repeated renders don't re-fetch const svgCache = new Map(); export default function PluginIcon({ pluginName, iconFile, className }: Props) { const url = iconFile ? `/api/plugins/${encodeURIComponent(pluginName)}/assets/${encodeURIComponent(iconFile)}` : ''; const [svg, setSvg] = useState(url ? (svgCache.get(url) ?? null) : null); useEffect(() => { if (!url || svgCache.has(url)) return; authenticatedFetch(url) .then((r) => { if (!r.ok) return; return r.text(); }) .then((text) => { if (text && text.trimStart().startsWith(' {}); }, [url]); if (!svg) return ; return ( ); }