Skip to content

Commit

Permalink
fix(nested): ensure unregister is called before register
Browse files Browse the repository at this point in the history
fixes #20516
closes #20603
  • Loading branch information
KaelWD committed Dec 16, 2024
1 parent ec269f2 commit d4ba559
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -493,14 +493,14 @@ export const VAutocomplete = genericComponent<new <
{ slots['prepend-item']?.() }

{ !displayItems.value.length && !props.hideNoData && (slots['no-data']?.() ?? (
<VListItem title={ t(props.noDataText) } />
<VListItem key="no-data" title={ t(props.noDataText) } />
))}

<VVirtualScroll ref={ vVirtualScrollRef } renderless items={ displayItems.value }>
{ ({ item, index, itemRef }) => {
const itemProps = mergeProps(item.props, {
ref: itemRef,
key: index,
key: item.value,
active: (highlightFirst.value && index === 0) ? true : undefined,
onClick: () => select(item, null),
})
Expand Down
4 changes: 2 additions & 2 deletions packages/vuetify/src/components/VCombobox/VCombobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -537,14 +537,14 @@ export const VCombobox = genericComponent<new <
{ slots['prepend-item']?.() }

{ !displayItems.value.length && !props.hideNoData && (slots['no-data']?.() ?? (
<VListItem title={ t(props.noDataText) } />
<VListItem key="no-data" title={ t(props.noDataText) } />
))}

<VVirtualScroll ref={ vVirtualScrollRef } renderless items={ displayItems.value }>
{ ({ item, index, itemRef }) => {
const itemProps = mergeProps(item.props, {
ref: itemRef,
key: index,
key: item.value,
active: (highlightFirst.value && index === 0) ? true : undefined,
onClick: () => select(item, null),
})
Expand Down
4 changes: 2 additions & 2 deletions packages/vuetify/src/components/VSelect/VSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -414,14 +414,14 @@ export const VSelect = genericComponent<new <
{ slots['prepend-item']?.() }

{ !displayItems.value.length && !props.hideNoData && (slots['no-data']?.() ?? (
<VListItem title={ t(props.noDataText) } />
<VListItem key="no-data" title={ t(props.noDataText) } />
))}

<VVirtualScroll ref={ vVirtualScrollRef } renderless items={ displayItems.value }>
{ ({ item, index, itemRef }) => {
const itemProps = mergeProps(item.props, {
ref: itemRef,
key: index,
key: item.value,
onClick: () => select(item, null),
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const VVirtualScroll = genericComponent<new <T, Renderless extends boolea
useRender(() => {
const children = computedItems.value.map(item => (
<VVirtualScrollItem
key={ item.index }
key={ item.key }
renderless={ props.renderless }
onUpdate:height={ height => handleItemResize(item.index, height) }
>
Expand Down
16 changes: 14 additions & 2 deletions packages/vuetify/src/composables/nested/nested.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@
import { useProxiedModel } from '@/composables/proxiedModel'

// Utilities
import { computed, inject, onBeforeUnmount, provide, ref, shallowRef, toRaw, toRef } from 'vue'
import {
computed,
inject,
onBeforeMount,
onBeforeUnmount,
provide,
ref,
shallowRef,
toRaw,
toRef,
} from 'vue'
import {
independentActiveStrategy,
independentSingleActiveStrategy,
Expand Down Expand Up @@ -334,7 +344,9 @@ export const useNestedItem = (id: Ref<unknown>, isGroup: boolean) => {
isGroupActivator: parent.isGroupActivator,
}

!parent.isGroupActivator && parent.root.register(computedId.value, parent.id.value, isGroup)
onBeforeMount(() => {
!parent.isGroupActivator && parent.root.register(computedId.value, parent.id.value, isGroup)
})

onBeforeUnmount(() => {
!parent.isGroupActivator && parent.root.unregister(computedId.value)
Expand Down
3 changes: 2 additions & 1 deletion packages/vuetify/src/composables/virtual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useResizeObserver } from '@/composables/resizeObserver'

// Utilities
import { computed, nextTick, onScopeDispose, ref, shallowRef, watch, watchEffect } from 'vue'
import { clamp, debounce, IN_BROWSER, propsFactory } from '@/util'
import { clamp, debounce, IN_BROWSER, isObject, propsFactory } from '@/util'

// Types
import type { Ref } from 'vue'
Expand Down Expand Up @@ -238,6 +238,7 @@ export function useVirtual <T> (props: VirtualProps, items: Ref<readonly T[]>) {
return items.value.slice(first.value, last.value).map((item, index) => ({
raw: item,
index: index + first.value,
key: (isObject(item) && 'value' in item) ? item.value : index + first.value,
}))
})

Expand Down

0 comments on commit d4ba559

Please sign in to comment.