diff --git a/components/utilities/helpful.js b/components/utilities/helpful.js index 16094529..4641e8ae 100644 --- a/components/utilities/helpful.js +++ b/components/utilities/helpful.js @@ -83,9 +83,14 @@ const Helpful = ({ slug, sourcefile }) => { setIsHelpful(true); }; + // Perform the route change cleanup function for the Helpful component inside a useEffect call, + // instead of using router.events.on("routeChangeComplete", handleRouteChange), because that + // adds new events progressively as you keep browsing the website, thus eventually leading to a memory leak. useEffect(() => { - router.events.on("routeChangeComplete", handleRouteChange); - }); + return () => { + handleRouteChange(); + }; + }, [sourcefile]); let joinedSlug = "/"; if (slug) {