Revert "fix(components): [table] render default slot only when it returns valid vnodes (#21651)" (#21728)

* revert: revert fix table slot rendering (#21651)

* Revert "fix(components): [table] render default slot only when it returns valid vnodes (#21651)"

This reverts commit 6bf6313f35.

---------

Co-authored-by: dopamine <coderzyou@gmail.com>
This commit is contained in:
ylcjwq
2025-08-13 21:02:11 +08:00
committed by GitHub
parent 2e50f05d0f
commit 38bc248a4c
2 changed files with 5 additions and 25 deletions

View File

@@ -1,4 +1,5 @@
import {
Comment,
computed,
getCurrentInstance,
h,
@@ -7,12 +8,7 @@ import {
unref,
watchEffect,
} from 'vue'
import {
debugWarn,
ensureValidVNode,
isArray,
isUndefined,
} from '@element-plus/utils'
import { debugWarn, isArray, isUndefined } from '@element-plus/utils'
import { useNamespace } from '@element-plus/hooks'
import {
cellForced,
@@ -164,7 +160,9 @@ function useRender<T extends DefaultRow>(
let children: VNode | VNode[] | null = null
if (slots.default) {
const vnodes = slots.default(data)
children = ensureValidVNode(vnodes) ? vnodes : originRenderCell(data)
children = vnodes.some((v) => v.type !== Comment)
? vnodes
: originRenderCell(data)
} else {
children = originRenderCell(data)
}

View File

@@ -170,21 +170,3 @@ export const flattedChildren = (
})
return result
}
// Copyied from https://github.com/vuejs/core/blob/c875019d49b4c36a88d929ccadc31ad414747c7b/packages/runtime-core/src/helpers/renderSlot.ts#L102
export function ensureValidVNode(
vnodes: VNodeArrayChildren
): VNodeArrayChildren | null {
return vnodes.some((child) => {
if (!isVNode(child)) return true
if (child.type === Comment) return false
if (
child.type === Fragment &&
!ensureValidVNode(child.children as VNodeArrayChildren)
)
return false
return true
})
? vnodes
: null
}