fix: mark live warnings seen reliably while panel is open

markAllSeen inside a watchEffect mutates its own dependency; the
recursion guard drops the subscription after a mount-time clear, so
warnings arriving while the panel was open stayed unseen. Use an
immediate watch instead and pin the regression in the component test
This commit is contained in:
pythongosssss
2026-07-10 05:39:48 -07:00
parent e5f242ed96
commit 83ea8d4e8a
2 changed files with 12 additions and 4 deletions

View File

@@ -266,6 +266,7 @@ describe('DeprecationWarningsTab', () => {
it('marks warnings seen as they arrive while the panel is open', async () => {
const store = useDeprecationWarningsStore()
store.report({ message: 'before mount' })
renderTab()
store.report({ message: 'arrived while open' })

View File

@@ -139,7 +139,7 @@
<script setup lang="ts">
import { useIntervalFn } from '@vueuse/core'
import type { MenuItem } from 'primevue/menuitem'
import { computed, ref, watch, watchEffect } from 'vue'
import { computed, ref, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import Badge from '@/components/common/Badge.vue'
@@ -231,7 +231,14 @@ function warningMenuItems(warning: { key: string }): MenuItem[] {
]
}
watchEffect(() => {
if (store.unseenCount > 0) store.markAllSeen()
})
// watch, not watchEffect: markAllSeen mutates the watched source, and a
// watchEffect's recursion guard drops the subscription after a mount-time
// clear, leaving warnings that arrive while the panel is open unseen forever.
watch(
() => store.unseenCount,
(count) => {
if (count > 0) store.markAllSeen()
},
{ immediate: true }
)
</script>