fix(branding): SVG (and .ico) favicons now render

DynamicFavicon hardcoded link.type='image/png', so an SVG/.ico favicon
was declared as PNG and browsers ignored it. Derive the type from the
file extension instead. (Sidebar icon already uses <img> which renders
SVG fine.)
This commit is contained in:
Luca
2026-06-03 13:38:52 +02:00
parent 44590b8c0b
commit a6e6ef7b83
@@ -14,13 +14,27 @@ export const DynamicFavicon: React.FC = () => {
const existingFavicons = document.querySelectorAll("link[rel*='icon']"); const existingFavicons = document.querySelectorAll("link[rel*='icon']");
existingFavicons.forEach(favicon => favicon.remove()); existingFavicons.forEach(favicon => favicon.remove());
// Create new favicon link // Create new favicon link. Derive the MIME type from the file
const link = document.createElement('link'); // extension — hardcoding image/png made SVG (and .ico) favicons
link.rel = 'icon'; // get declared as PNG, which browsers reject (favicon didn't show).
link.type = 'image/png'; const href = settings.branding_favicon_url.startsWith('http')
link.href = settings.branding_favicon_url.startsWith('http')
? settings.branding_favicon_url ? settings.branding_favicon_url
: buildResourceUrl(settings.branding_favicon_url); : buildResourceUrl(settings.branding_favicon_url);
const ext = href.split('?')[0].split('.').pop()?.toLowerCase();
const typeByExt: Record<string, string> = {
svg: 'image/svg+xml',
png: 'image/png',
ico: 'image/x-icon',
gif: 'image/gif',
jpg: 'image/jpeg',
jpeg: 'image/jpeg',
webp: 'image/webp',
};
const link = document.createElement('link');
link.rel = 'icon';
if (ext && typeByExt[ext]) link.type = typeByExt[ext];
link.href = href;
document.head.appendChild(link); document.head.appendChild(link);
} }