Skip to content

Commit 7168e39

Browse files
committed
docs(useMutationObserver): fix infinite loop on SPA navigation in basic example
1 parent d4ed58d commit 7168e39

File tree

1 file changed

+6
-3
lines changed
  • apps/docs/src/examples/composables/use-mutation-observer

1 file changed

+6
-3
lines changed

apps/docs/src/examples/composables/use-mutation-observer/basic.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
import { useMutationObserver } from '@vuetify/v0'
3-
import { ref, useTemplateRef } from 'vue'
3+
import { ref, shallowRef, useTemplateRef } from 'vue'
44
55
interface MutationEntry {
66
type: string
@@ -9,7 +9,8 @@
99
1010
const target = useTemplateRef<HTMLElement>('target')
1111
const mutations = ref<MutationEntry[]>([])
12-
const childCount = ref(0)
12+
const childCount = shallowRef(0)
13+
const activeChildren = shallowRef(0)
1314
1415
const { isPaused, pause, resume } = useMutationObserver(
1516
target,
@@ -60,12 +61,14 @@
6061
child.textContent = `Child ${childCount.value}`
6162
child.className = 'px-3 py-1 rounded bg-surface-variant text-on-surface-variant text-sm'
6263
el.append(child)
64+
activeChildren.value++
6365
}
6466
6567
function onRemoveChild () {
6668
const el = target.value
6769
if (!el?.lastElementChild) return
6870
el.lastElementChild.remove()
71+
activeChildren.value--
6972
}
7073
7174
function onToggleAttribute () {
@@ -116,7 +119,7 @@
116119
class="min-h-16 p-3 rounded-lg border-2 border-dashed border-divider flex flex-wrap gap-2 items-start"
117120
>
118121
<span
119-
v-if="!target?.children.length"
122+
v-if="activeChildren === 0"
120123
class="text-sm text-on-surface-variant opacity-60"
121124
>
122125
Add children to observe mutations

0 commit comments

Comments
 (0)