diff --git a/packages/vuetify/src/composables/nested/nested.ts b/packages/vuetify/src/composables/nested/nested.ts index 5f80f4da090..753f159fddc 100644 --- a/packages/vuetify/src/composables/nested/nested.ts +++ b/packages/vuetify/src/composables/nested/nested.ts @@ -18,6 +18,7 @@ import { leafSingleSelectStrategy, } from './selectStrategies' import { getCurrentInstance, getUid, propsFactory } from '@/util' +import { preventLoops } from '@/util/nested' // Types import type { InjectionKey, PropType, Ref } from 'vue' @@ -182,6 +183,7 @@ export const useNested = (props: NestedProps) => { let parent: unknown = id while (parent != null) { + preventLoops(path, parent) path.unshift(parent) parent = parents.value.get(parent) } diff --git a/packages/vuetify/src/labs/VTreeview/VTreeview.tsx b/packages/vuetify/src/labs/VTreeview/VTreeview.tsx index d4079447da0..237c0543a1b 100644 --- a/packages/vuetify/src/labs/VTreeview/VTreeview.tsx +++ b/packages/vuetify/src/labs/VTreeview/VTreeview.tsx @@ -10,6 +10,7 @@ import { useProxiedModel } from '@/composables/proxiedModel' // Utilities import { computed, provide, ref, toRaw, toRef } from 'vue' import { genericComponent, omit, propsFactory, useRender } from '@/util' +import { preventLoops } from '@/util/nested' // Types import { VTreeviewSymbol } from './shared' @@ -98,6 +99,7 @@ export const VTreeview = genericComponent( const path: unknown[] = [] let parent: unknown = id while (parent != null) { + preventLoops(path, parent) path.unshift(parent) parent = vListRef.value?.parents.get(parent) } diff --git a/packages/vuetify/src/util/nested.ts b/packages/vuetify/src/util/nested.ts new file mode 100644 index 00000000000..488e144c9ef --- /dev/null +++ b/packages/vuetify/src/util/nested.ts @@ -0,0 +1,9 @@ +export function preventLoops (path: T[] | Set | Map, itemToPush: T) { + if ( + (Array.isArray(path) && path.includes(itemToPush)) || + (path instanceof Set && path.has(itemToPush)) || + (path instanceof Map && path.has(itemToPush)) + ) { + throw new Error('[Vuetify] Could not resolve nested path because of duplicated identifiers') + } +}