Skip to content

Commit 6560e8c

Browse files
davila7claude
andcommitted
fix: Fix dashboard icons and simplify data loading
- TypeIcon: use inline SVG instead of DOMParser (broke SSR hydration) - Remove placeholder components.json (not needed, fetches from prod URL) - Simplify COMPONENTS_JSON_URL to always use www.aitmpl.com Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 71d0b3d commit 6560e8c

File tree

3 files changed

+8
-25
lines changed

3 files changed

+8
-25
lines changed

dashboard/public/components.json

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,15 @@
1-
import { useRef, useEffect } from 'react';
21
import { ICONS } from '../lib/icons';
32

43
/**
5-
* Safely renders a type icon SVG without dangerouslySetInnerHTML.
6-
* Parses the SVG string via DOMParser and only inserts valid SVG elements.
4+
* Renders a type icon SVG inline.
5+
* Safe to use dangerouslySetInnerHTML here because ICONS are hardcoded
6+
* SVG strings defined in icons.ts — not user-supplied data.
77
*/
88
export default function TypeIcon({ type, size = 16, className = '' }: { type: string; size?: number; className?: string }) {
9-
const ref = useRef<HTMLSpanElement>(null);
9+
const svg = ICONS[type];
10+
if (!svg) return <span className={className} />;
1011

11-
useEffect(() => {
12-
const el = ref.current;
13-
if (!el) return;
12+
const sized = svg.replace(/width="16"/, `width="${size}"`).replace(/height="16"/, `height="${size}"`);
1413

15-
const svgStr = ICONS[type];
16-
if (!svgStr) return;
17-
18-
const doc = new DOMParser().parseFromString(svgStr, 'image/svg+xml');
19-
const svg = doc.querySelector('svg');
20-
21-
el.innerHTML = '';
22-
if (svg && !doc.querySelector('parsererror')) {
23-
svg.setAttribute('width', String(size));
24-
svg.setAttribute('height', String(size));
25-
el.appendChild(document.importNode(svg, true));
26-
}
27-
}, [type, size]);
28-
29-
return <span ref={ref} className={className} />;
14+
return <span className={className} dangerouslySetInnerHTML={{ __html: sized }} />;
3015
}

dashboard/src/lib/constants.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import type { FeaturedItem } from './types';
22

33
export const COMPONENTS_JSON_URL =
4-
import.meta.env.PUBLIC_COMPONENTS_JSON_URL ??
5-
(import.meta.env.DEV ? '/components.json' : 'https://www.aitmpl.com/components.json');
4+
import.meta.env.PUBLIC_COMPONENTS_JSON_URL ?? 'https://www.aitmpl.com/components.json';
65

76
export const ITEMS_PER_PAGE = 24;
87

0 commit comments

Comments
 (0)