From effd287e9a22b995771a7d49bee81e85ce84f87e Mon Sep 17 00:00:00 2001 From: waliser Date: Wed, 19 Aug 2026 18:01:27 +0700 Subject: [PATCH] fix(app): clean up online/offline listeners on Browse.vue unmount Browse.vue registers window 'online'/'offline' listeners but never removes them. Since only LibraryPage is kept alive by the router, Browse unmounts every time the user navigates away (e.g. into a project) and remounts on return, leaking a new pair of closures (and pinning the whole component scope) on window each time. Over a browsing session this accumulates continuously. --- apps/app-frontend/src/pages/Browse.vue | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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({