Fix memory leaks from Tippy.js instances and unremoved event listeners

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-09 13:54:38 +08:00
parent 9acd722929
commit 881dccc1ab
5 changed files with 48 additions and 21 deletions

View File

@@ -465,7 +465,7 @@
* and file operations (rename, delete).
*/
import { ref, computed, watch, onMounted } from "vue";
import { ref, computed, watch, onMounted, onBeforeUnmount } from "vue";
import { useRouter } from "vue-router";
import { storeToRefs } from "pinia";
import { useMapCompareStore } from "@/stores/mapCompareStore";
@@ -917,19 +917,29 @@ function getGridSortData(event) {
}
}
/**
* Clears the active file selection when clicking outside a list item.
* @param {MouseEvent} e - The click event.
*/
const handleWindowClick = (e) => {
const clickedLi = e.target.closest("li");
if (!clickedLi || !clickedLi.id.startsWith("li")) isActive.value = null;
};
// Mounted
onMounted(() => {
isLoading.value = true;
store.fetchAllFiles();
window.addEventListener("click", (e) => {
const clickedLi = e.target.closest("li");
if (!clickedLi || !clickedLi.id.startsWith("li")) isActive.value = null;
});
window.addEventListener("click", handleWindowClick);
// Add the .scrollbar class to the DataTable tbody
const tbodyElement = document.querySelector(".p-datatable-tbody");
tbodyElement?.classList.add("scrollbar");
isLoading.value = false;
});
onBeforeUnmount(() => {
window.removeEventListener("click", handleWindowClick);
});
</script>
<style scoped>
@reference "../../assets/tailwind.css";