mirror of
https://github.com/modrinth/code.git
synced 2026-08-25 17:14:50 +00:00
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:
@@ -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({
|
||||||
|
|||||||
Reference in New Issue
Block a user