fix(app): clean up online/offline listeners on Browse unmount (#7213)

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.
This commit is contained in:
wal
2026-08-20 18:06:36 +00:00
committed by GitHub
parent 8eb12d5d24
commit c94034f4e2
+11 -4
View File
@@ -34,7 +34,7 @@ import {
} from '@modrinth/ui' } from '@modrinth/ui'
import { useQuery, useQueryClient } from '@tanstack/vue-query' import { useQuery, useQueryClient } from '@tanstack/vue-query'
import type { Ref } from 'vue' 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 type { LocationQuery } from 'vue-router'
import { useRoute, useRouter } from 'vue-router' import { useRoute, useRouter } from 'vue-router'
@@ -530,13 +530,20 @@ const {
}) })
const offline = ref(!navigator.onLine) const offline = ref(!navigator.onLine)
window.addEventListener('offline', () => { const handleOffline = () => {
debugLog('went offline') debugLog('went offline')
offline.value = true offline.value = true
}) }
window.addEventListener('online', () => { const handleOnline = () => {
debugLog('went online') debugLog('went online')
offline.value = false offline.value = false
}
window.addEventListener('offline', handleOffline)
window.addEventListener('online', handleOnline)
onBeforeUnmount(() => {
window.removeEventListener('offline', handleOffline)
window.removeEventListener('online', handleOnline)
}) })
const messages = defineMessages({ const messages = defineMessages({