Skip to content
This repository has been archived by the owner on May 17, 2023. It is now read-only.

Fix helpful.js memory leak #176

Open
wants to merge 1 commit into
base: publish
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions components/utilities/helpful.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down