From 7cf160e4bc02f1c41017e7ef4dda2d8933481823 Mon Sep 17 00:00:00 2001 From: Morgan Bentell Date: Wed, 1 Mar 2023 13:55:58 +0100 Subject: [PATCH] cancel debounced function on unmount to avoid updating state on an umounted component Signed-off-by: Morgan Bentell --- plugins/techdocs-react/src/hooks.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/techdocs-react/src/hooks.ts b/plugins/techdocs-react/src/hooks.ts index e8cc7bddc8..42d8f0fbc1 100644 --- a/plugins/techdocs-react/src/hooks.ts +++ b/plugins/techdocs-react/src/hooks.ts @@ -82,6 +82,8 @@ export const useShadowRootSelection = (waitMillis: number = 0) => { [shadowRoot, setSelection, waitMillis], ); + useEffect(() => handleSelectionChange.cancel); + useEffect(() => { window.document.addEventListener('selectionchange', handleSelectionChange); return () =>