()
| 44 | }; |
| 45 | |
| 46 | const loadCode = async () => { |
| 47 | try { |
| 48 | const response = await fetch(`/origin/r/${component.name}.json`); |
| 49 | if (!response.ok) { |
| 50 | handleEmptyCode(); |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | const contentType = response.headers.get("content-type"); |
| 55 | if (!contentType || !contentType.includes("application/json")) { |
| 56 | handleEmptyCode(); |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | const data = await response.json(); |
| 61 | const codeContent = convertRegistryPaths(data.files[0].content) || ""; |
| 62 | setCode(codeContent); |
| 63 | |
| 64 | // Pre-highlight the code |
| 65 | const highlighted = await highlight(codeContent, "tsx"); |
| 66 | setHighlightedCode(highlighted); |
| 67 | } catch (error) { |
| 68 | console.error("Failed to load code:", error); |
| 69 | handleEmptyCode(); |
| 70 | } |
| 71 | }; |
| 72 | |
| 73 | loadCode(); |
| 74 | }, [component.name]); |
no test coverage detected