mirror of
https://github.com/TecharoHQ/anubis.git
synced 2026-04-19 14:46:39 +00:00
fix(js/main): add cleanup for toggle event listener in useEffect
The useEffect registered a toggle listener on the <details> element but never removed it, which could leak handlers on remounts or in tests. Extract the handler to a named function and return a cleanup that calls removeEventListener. Assisted-by: Claude Opus 4.6 via Claude Code Signed-off-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
+12
-5
@@ -109,12 +109,13 @@ function App({ anubisVersion, basePrefix }: AppProps) {
|
|||||||
// Main initialization
|
// Main initialization
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const details = document.querySelector("details");
|
const details = document.querySelector("details");
|
||||||
|
const onToggle = () => {
|
||||||
|
if (details?.open) {
|
||||||
|
detailsRead.current = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
if (details) {
|
if (details) {
|
||||||
details.addEventListener("toggle", () => {
|
details.addEventListener("toggle", onToggle);
|
||||||
if (details.open) {
|
|
||||||
detailsRead.current = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const showError = (title: string, message: string, imageSrc: string) => {
|
const showError = (title: string, message: string, imageSrc: string) => {
|
||||||
@@ -243,6 +244,12 @@ function App({ anubisVersion, basePrefix }: AppProps) {
|
|||||||
imageURL("reject", anubisVersion, basePrefix),
|
imageURL("reject", anubisVersion, basePrefix),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (details) {
|
||||||
|
details.removeEventListener("toggle", onToggle);
|
||||||
|
}
|
||||||
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const pensiveURL = imageURL("pensive", anubisVersion, basePrefix);
|
const pensiveURL = imageURL("pensive", anubisVersion, basePrefix);
|
||||||
|
|||||||
Reference in New Issue
Block a user