Skip to content

Commit

Permalink
set tool search worker to null to remove references while unmounted
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedhamidawan committed Mar 28, 2024
1 parent 0d75267 commit 4f0f753
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
11 changes: 9 additions & 2 deletions client/src/components/Panels/Common/ToolSearch.vue
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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);
Expand All @@ -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,
() => {
Expand Down
5 changes: 0 additions & 5 deletions client/src/stores/toolStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 4f0f753

Please sign in to comment.