From 17b6ea4266570c59abbf7173bb955074cc500068 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Wed, 22 Nov 2023 14:45:49 +0100 Subject: [PATCH 1/2] fix(core): Cleanup spotlight event target listeners --- packages/core/src/App.tsx | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/core/src/App.tsx b/packages/core/src/App.tsx index 220cc6b8..847b9e53 100644 --- a/packages/core/src/App.tsx +++ b/packages/core/src/App.tsx @@ -56,13 +56,23 @@ export default function App({ }; }, [integrations, sidecar]); - eventTarget.addEventListener('open', () => { - setOpen(true); - }); + useEffect(() => { + const onOpen = () => { + setOpen(true); + }; + + const onClose = () => { + setOpen(false); + }; - eventTarget.addEventListener('close', () => { - setOpen(false); - }); + eventTarget.addEventListener('open', onOpen); + eventTarget.addEventListener('close', onClose); + + return () => { + eventTarget.removeEventListener('open', onOpen); + eventTarget.removeEventListener('close', onClose); + }; + }, [eventTarget]); useEffect(() => { if (!isOpen) { From 413cc944265361800071eef26ccbe997e9efe217 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Wed, 22 Nov 2023 14:48:25 +0100 Subject: [PATCH 2/2] changeset --- .changeset/seven-carrots-shop.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/seven-carrots-shop.md diff --git a/.changeset/seven-carrots-shop.md b/.changeset/seven-carrots-shop.md new file mode 100644 index 00000000..763039ca --- /dev/null +++ b/.changeset/seven-carrots-shop.md @@ -0,0 +1,5 @@ +--- +'@spotlightjs/core': patch +--- + +fix(core): Use effect and cleanup spotlight event target listeners