From 1e6df136d8202c8adf65948527f4c3e7583b338c Mon Sep 17 00:00:00 2001
From: nsfisis <nsfisis@gmail.com>
Date: Tue, 4 Mar 2025 22:55:01 +0900
Subject: websocket to polling

---
 frontend/app/components/Gaming/CodeBlock.tsx | 31 +++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)

(limited to 'frontend/app/components/Gaming/CodeBlock.tsx')

diff --git a/frontend/app/components/Gaming/CodeBlock.tsx b/frontend/app/components/Gaming/CodeBlock.tsx
index b7d45c0..0a9a2e5 100644
--- a/frontend/app/components/Gaming/CodeBlock.tsx
+++ b/frontend/app/components/Gaming/CodeBlock.tsx
@@ -1,8 +1,5 @@
-import Prism, { highlight, languages } from "prismjs";
-import "prismjs/components/prism-swift";
-import "prismjs/themes/prism.min.css";
-
-Prism.manual = true;
+import { useEffect, useState } from "react";
+import { codeToHtml } from "shiki";
 
 type Props = {
 	code: string;
@@ -10,11 +7,31 @@ type Props = {
 };
 
 export default function CodeBlock({ code, language }: Props) {
-	const highlighted = highlight(code, languages[language]!, language);
+	const [highlightedCode, setHighlightedCode] = useState<string | null>(null);
+
+	useEffect(() => {
+		let isMounted = true;
+
+		(async () => {
+			const highlighted = await codeToHtml(code, {
+				lang: language,
+				theme: "github-light",
+			});
+			if (isMounted) {
+				setHighlightedCode(highlighted);
+			}
+		})();
+
+		return () => {
+			isMounted = false;
+		};
+	}, [code, language]);
 
 	return (
 		<pre className="h-full w-full p-2 bg-gray-50 rounded-lg border border-gray-300 whitespace-pre-wrap break-words">
-			<code dangerouslySetInnerHTML={{ __html: highlighted }} />
+			{highlightedCode === null ? null : (
+				<code dangerouslySetInnerHTML={{ __html: highlightedCode }} />
+			)}
 		</pre>
 	);
 }
-- 
cgit v1.2.3-70-g09d2

