diff --git a/apps/app-frontend/src/pages/Browse.vue b/apps/app-frontend/src/pages/Browse.vue index 0a7a18263d..22a3da191c 100644 --- a/apps/app-frontend/src/pages/Browse.vue +++ b/apps/app-frontend/src/pages/Browse.vue @@ -34,7 +34,7 @@ import { } from '@modrinth/ui' import { useQuery, useQueryClient } from '@tanstack/vue-query' import type { Ref } from 'vue' -import { computed, ref, shallowRef, watch } from 'vue' +import { computed, onBeforeUnmount, ref, shallowRef, watch } from 'vue' import type { LocationQuery } from 'vue-router' import { useRoute, useRouter } from 'vue-router' @@ -530,13 +530,20 @@ const { }) const offline = ref(!navigator.onLine) -window.addEventListener('offline', () => { +const handleOffline = () => { debugLog('went offline') offline.value = true -}) -window.addEventListener('online', () => { +} +const handleOnline = () => { debugLog('went online') offline.value = false +} +window.addEventListener('offline', handleOffline) +window.addEventListener('online', handleOnline) + +onBeforeUnmount(() => { + window.removeEventListener('offline', handleOffline) + window.removeEventListener('online', handleOnline) }) const messages = defineMessages({