From a82154de3f8a1c701f254bf8c14300853dab4c81 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sun, 23 Jun 2024 23:15:24 -0700 Subject: [PATCH] refac --- src/lib/components/chat/Chat.svelte | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 621dc827e..4e7fac921 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -127,7 +127,7 @@ } onMount(async () => { - window.addEventListener('message', async (event) => { + const onMessageHandler = async (event) => { if (event.origin === window.origin) { // Replace with your iframe's origin console.log('Message received from iframe:', event.data); @@ -160,7 +160,8 @@ } } } - }); + }; + window.addEventListener('message', onMessageHandler); if (!$chatId) { chatId.subscribe(async (value) => { @@ -173,6 +174,10 @@ await goto('/'); } } + + return () => { + window.removeEventListener('message', onMessageHandler); + }; }); //////////////////////////