Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-core): recursive querying of fragments when find singleRoot #10092

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions packages/runtime-core/src/componentRenderUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from './component'
import {
Comment,
Fragment,
type VNode,
type VNodeArrayChildren,
blockStack,
Expand Down Expand Up @@ -266,10 +267,13 @@ export function renderComponentRoot(
const getChildRoot = (vnode: VNode): [VNode, SetRootFn] => {
const rawChildren = vnode.children as VNodeArrayChildren
const dynamicChildren = vnode.dynamicChildren
const childRoot = filterSingleRoot(rawChildren)
let childRoot = filterSingleRoot(rawChildren, true)
if (!childRoot) {
return [vnode, undefined]
}
if (childRoot.type === Fragment) {
return getChildRoot(childRoot)
}
const index = rawChildren.indexOf(childRoot)
const dynamicIndex = dynamicChildren ? dynamicChildren.indexOf(childRoot) : -1
const setRoot: SetRootFn = (updatedRoot: VNode) => {
Expand All @@ -287,6 +291,7 @@ const getChildRoot = (vnode: VNode): [VNode, SetRootFn] => {

export function filterSingleRoot(
children: VNodeArrayChildren,
needSetRoot = false,
): VNode | undefined {
let singleRoot
for (let i = 0; i < children.length; i++) {
Expand All @@ -298,7 +303,13 @@ export function filterSingleRoot(
// has more than 1 non-comment child, return now
return
} else {
singleRoot = child
if (!needSetRoot && child.type === Fragment) {
singleRoot = filterSingleRoot(
(child.children as VNodeArrayChildren) ?? [],
)
} else {
singleRoot = child
}
}
}
} else {
Expand Down