From da6268911cb39c9f950f3ceb4940dc711acdd1e9 Mon Sep 17 00:00:00 2001 From: Alexey Pyltsyn Date: Fri, 16 Oct 2020 19:15:48 +0300 Subject: [PATCH] fix(v2): remove event listeners on Tabs component unmount (#3599) --- packages/docusaurus-theme-bootstrap/src/theme/Tabs/index.tsx | 5 +++++ packages/docusaurus-theme-classic/src/theme/Tabs/index.tsx | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/packages/docusaurus-theme-bootstrap/src/theme/Tabs/index.tsx b/packages/docusaurus-theme-bootstrap/src/theme/Tabs/index.tsx index 7b9fcc93d3..3f71929a6b 100644 --- a/packages/docusaurus-theme-bootstrap/src/theme/Tabs/index.tsx +++ b/packages/docusaurus-theme-bootstrap/src/theme/Tabs/index.tsx @@ -106,6 +106,11 @@ function Tabs(props: Props): JSX.Element { useEffect(() => { window.addEventListener('keydown', handleKeyboardEvent); window.addEventListener('mousedown', handleMouseEvent); + + return () => { + window.removeEventListener('keydown', handleKeyboardEvent); + window.removeEventListener('mousedown', handleMouseEvent); + }; }, []); return ( diff --git a/packages/docusaurus-theme-classic/src/theme/Tabs/index.tsx b/packages/docusaurus-theme-classic/src/theme/Tabs/index.tsx index 6587d5cae5..29d7b1ca05 100644 --- a/packages/docusaurus-theme-classic/src/theme/Tabs/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Tabs/index.tsx @@ -93,6 +93,11 @@ function Tabs(props: Props): JSX.Element { useEffect(() => { window.addEventListener('keydown', handleKeyboardEvent); window.addEventListener('mousedown', handleMouseEvent); + + return () => { + window.removeEventListener('keydown', handleKeyboardEvent); + window.removeEventListener('mousedown', handleMouseEvent); + }; }, []); return (