set tool search worker to null to remove references while unmounted

This commit is contained in:
Ahmed Awan
2024-03-28 13:40:59 -05:00
parent 0d752671c2
commit 4f0f753097
2 changed files with 9 additions and 7 deletions
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { BAlert } from "bootstrap-vue";
import { storeToRefs } from "pinia";
import { computed, type ComputedRef, onMounted, type PropType, watch } from "vue";
import { computed, type ComputedRef, onMounted, onUnmounted, type PropType, watch } from "vue";
import { useRouter } from "vue-router/composables";
import { type Tool, type ToolSection, useToolStore } from "@/stores/toolStore";
@@ -124,7 +124,7 @@ onMounted(() => {
if (!searchWorker.value) {
searchWorker.value = new Worker(new URL("components/Panels/toolSearch.worker.js", import.meta.url));
}
searchWorker.value!.onmessage = ({ data }) => {
searchWorker.value.onmessage = ({ data }) => {
const { type, payload, sectioned, query, closestTerm } = data;
if (type === "searchToolsByKeysResult" && query === props.query) {
emit("onResults", payload, sectioned, closestTerm);
@@ -136,6 +136,13 @@ onMounted(() => {
};
});
onUnmounted(() => {
// The worker is not terminated but it will not be listening to messages
if (searchWorker.value?.onmessage) {
searchWorker.value.onmessage = null;
}
});
watch(
() => currentFavorites.value.tools,
() => {
-5
View File
@@ -82,11 +82,6 @@ export const useToolStore = defineStore("toolStore", () => {
const loading = ref(false);
const searchWorker = ref<Worker | undefined>(undefined);
// TODO: Where do we terminate the worker?
// onScopeDispose(() => {
// searchWorker.value?.terminate();
// searchWorker.value = undefined;
// });
const getToolForId = computed(() => {
return (toolId: string) => toolsById.value[toolId];