Skip to content

Commit

Permalink
fix: use hasOwnProperty to check dynamic slot presence
Browse files Browse the repository at this point in the history
fixes #14425
  • Loading branch information
KaelWD committed Nov 23, 2021
1 parent 958d4e6 commit ca4cbda
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/vuetify/src/components/VDataTable/MobileRow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export default Vue.extend({
const value = getObjectValueByPath(props.item, header.value)

const slotName = header.value
const scopedSlot = data.scopedSlots && data.scopedSlots[slotName]
const regularSlot = computedSlots[slotName]
const scopedSlot = data.scopedSlots && data.scopedSlots.hasOwnProperty(slotName) && data.scopedSlots[slotName]
const regularSlot = computedSlots.hasOwnProperty(slotName) && computedSlots[slotName]

if (scopedSlot) {
children.push(scopedSlot({
Expand Down
4 changes: 2 additions & 2 deletions packages/vuetify/src/components/VDataTable/Row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export default Vue.extend({
const value = getObjectValueByPath(props.item, header.value)

const slotName = header.value
const scopedSlot = data.scopedSlots && data.scopedSlots[slotName]
const regularSlot = computedSlots[slotName]
const scopedSlot = data.scopedSlots && data.scopedSlots.hasOwnProperty(slotName) && data.scopedSlots[slotName]
const regularSlot = computedSlots.hasOwnProperty(slotName) && computedSlots[slotName]

if (scopedSlot) {
children.push(...wrapInArray(scopedSlot({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default mixins(header).extend({
}

children.push(
this.$scopedSlots[header.value]
this.$scopedSlots.hasOwnProperty(header.value)
? this.$scopedSlots[header.value]!({ header })
: this.$createElement('span', [header.text])
)
Expand Down
10 changes: 5 additions & 5 deletions packages/vuetify/src/util/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,11 @@ export function searchItems<T extends any = any> (items: T[], search: string): T
* - 'v-slot' for unbound v-slot (`#default`) - only if the third param is true, otherwise counts as scoped
*/
export function getSlotType<T extends boolean = false> (vm: Vue, name: string, split?: T): (T extends true ? 'v-slot' : never) | 'normal' | 'scoped' | void {
if (vm.$slots[name] && vm.$scopedSlots[name] && (vm.$scopedSlots[name] as any).name) {
if (vm.$slots.hasOwnProperty(name) && vm.$scopedSlots.hasOwnProperty(name) && (vm.$scopedSlots[name] as any).name) {
return split ? 'v-slot' as any : 'scoped'
}
if (vm.$slots[name]) return 'normal'
if (vm.$scopedSlots[name]) return 'scoped'
if (vm.$slots.hasOwnProperty(name)) return 'normal'
if (vm.$scopedSlots.hasOwnProperty(name)) return 'scoped'
}

export function debounce (fn: Function, delay: number) {
Expand Down Expand Up @@ -419,9 +419,9 @@ export function getPrefixedScopedSlots (prefix: string, scopedSlots: any) {
}

export function getSlot (vm: Vue, name = 'default', data?: object | (() => object), optional = false) {
if (vm.$scopedSlots[name]) {
if (vm.$scopedSlots.hasOwnProperty(name)) {
return vm.$scopedSlots[name]!(data instanceof Function ? data() : data)
} else if (vm.$slots[name] && (!data || optional)) {
} else if (vm.$slots.hasOwnProperty(name) && (!data || optional)) {
return vm.$slots[name]
}
return undefined
Expand Down

0 comments on commit ca4cbda

Please sign in to comment.