From 701b5a1dec7aa6be5eddd4b6dcbf915b553ed6dc Mon Sep 17 00:00:00 2001 From: tamaina Date: Mon, 22 Nov 2021 16:01:28 +0900 Subject: [PATCH] fix notification.vue --- packages/client/src/components/notification.vue | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/client/src/components/notification.vue b/packages/client/src/components/notification.vue index 89025b72e6..5e743df246 100644 --- a/packages/client/src/components/notification.vue +++ b/packages/client/src/components/notification.vue @@ -107,11 +107,8 @@ export default defineComponent({ const reactionRef = ref(null); onMounted(() => { - let readObserver: IntersectionObserver | null = null; - let connection = null; - if (!props.notification.isRead) { - readObserver = new IntersectionObserver((entries, observer) => { + const readObserver = new IntersectionObserver((entries, observer) => { if (!entries.some(entry => entry.isIntersecting)) return; os.stream.send('readNotification', { id: props.notification.id @@ -121,14 +118,15 @@ export default defineComponent({ readObserver.observe(elRef.value); - connection = os.stream.useChannel('main'); + const connection = os.stream.useChannel('main'); connection.on('readAllNotifications', () => readObserver.unobserve(elRef.value)); + + onUnmounted(() => { + if (readObserver) readObserver.unobserve(elRef.value); + if (connection) connection.dispose(); + }); } - onUnmounted(() => { - if (readObserver) readObserver.unobserve(elRef.value); - if (connection) connection.dispose(); - }); }); const followRequestDone = ref(false);