diff --git a/app/components/ChatWidget.tsx b/app/components/ChatWidget.tsx index e18efe0..2bb3407 100644 --- a/app/components/ChatWidget.tsx +++ b/app/components/ChatWidget.tsx @@ -51,6 +51,14 @@ export default function ChatWidget() { } }, [isOpen]); + // Helper function to decode HTML entities + const decodeHtmlEntities = (text: string): string => { + if (!text || typeof text !== 'string') return text; + const textarea = document.createElement('textarea'); + textarea.innerHTML = text; + return textarea.value; + }; + // Load messages from localStorage useEffect(() => { if (typeof window !== "undefined") { @@ -61,6 +69,7 @@ export default function ChatWidget() { setMessages( parsed.map((m: Message) => ({ ...m, + text: decodeHtmlEntities(m.text), // Decode HTML entities when loading timestamp: new Date(m.timestamp), })), ); @@ -72,7 +81,7 @@ export default function ChatWidget() { setMessages([ { id: "welcome", - text: "Hi! I'm Dennis's AI assistant. Ask me anything about his skills, projects, or experience! 🚀", + text: "Hi! I'm Dennis's AI assistant. Ask me anything about his skills, projects, or experience! 🚀", sender: "bot", timestamp: new Date(), }, @@ -128,12 +137,8 @@ export default function ChatWidget() { // Decode HTML entities in the reply let replyText = data.reply || "Sorry, I couldn't process that. Please try again."; - // Decode HTML entities client-side as well (double safety) - if (typeof window !== 'undefined') { - const textarea = document.createElement('textarea'); - textarea.innerHTML = replyText; - replyText = textarea.value; - } + // Decode HTML entities client-side (double safety) + replyText = decodeHtmlEntities(replyText); const botMessage: Message = { id: (Date.now() + 1).toString(), @@ -237,7 +242,7 @@ export default function ChatWidget() {
Always online