Skip to content

Commit

Permalink
fix(nested): Prevent infinite loops in getPath
Browse files Browse the repository at this point in the history
  • Loading branch information
jsek committed Aug 27, 2024
1 parent 0b018d9 commit e2656c9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/vuetify/src/composables/nested/nested.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions packages/vuetify/src/labs/VTreeview/VTreeview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -98,6 +99,7 @@ export const VTreeview = genericComponent<new <T>(
const path: unknown[] = []
let parent: unknown = id
while (parent != null) {
preventLoops(path, parent)
path.unshift(parent)
parent = vListRef.value?.parents.get(parent)
}
Expand Down
9 changes: 9 additions & 0 deletions packages/vuetify/src/util/nested.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export function preventLoops<T> (path: T[] | Set<T> | Map<T, any>, 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')
}
}

0 comments on commit e2656c9

Please # to comment.