MCPcopy
hub / github.com/vuejs/core / getChildRoot

Function getChildRoot

packages/runtime-core/src/componentRenderUtils.ts:283–310  ·  view source on GitHub ↗
(vnode: VNode)

Source from the content-addressed store, hash-verified

281 * root for attrs and scope id processing.
282 */
283const getChildRoot = (vnode: VNode): [VNode, SetRootFn] => {
284 const rawChildren = vnode.children as VNodeArrayChildren
285 const dynamicChildren = vnode.dynamicChildren
286 const childRoot = filterSingleRoot(rawChildren, false)
287 if (!childRoot) {
288 return [vnode, undefined]
289 } else if (
290 __DEV__ &&
291 childRoot.patchFlag > 0 &&
292 childRoot.patchFlag & PatchFlags.DEV_ROOT_FRAGMENT
293 ) {
294 return getChildRoot(childRoot)
295 }
296
297 const index = rawChildren.indexOf(childRoot)
298 const dynamicIndex = dynamicChildren ? dynamicChildren.indexOf(childRoot) : -1
299 const setRoot: SetRootFn = (updatedRoot: VNode) => {
300 rawChildren[index] = updatedRoot
301 if (dynamicChildren) {
302 if (dynamicIndex > -1) {
303 dynamicChildren[dynamicIndex] = updatedRoot
304 } else if (updatedRoot.patchFlag > 0) {
305 vnode.dynamicChildren = [...dynamicChildren, updatedRoot]
306 }
307 }
308 }
309 return [normalizeVNode(childRoot), setRoot]
310}
311
312export function filterSingleRoot(
313 children: VNodeArrayChildren,

Callers 1

renderComponentRootFunction · 0.85

Calls 3

normalizeVNodeFunction · 0.90
filterSingleRootFunction · 0.85
indexOfMethod · 0.80

Tested by

no test coverage detected