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

Function renderSlot

packages/runtime-core/src/helpers/renderSlot.ts:25–101  ·  view source on GitHub ↗
(
  slots: Slots,
  name: string,
  props: Data = {},
  // this is not a user-facing function, so the fallback is always generated by
  // the compiler and guaranteed to be a function returning an array
  fallback?: () => VNodeArrayChildren,
  noSlotted?: boolean,
)

Source from the content-addressed store, hash-verified

23 * @private
24 */
25export function renderSlot(
26 slots: Slots,
27 name: string,
28 props: Data = {},
29 // this is not a user-facing function, so the fallback is always generated by
30 // the compiler and guaranteed to be a function returning an array
31 fallback?: () => VNodeArrayChildren,
32 noSlotted?: boolean,
33): VNode {
34 if (
35 currentRenderingInstance!.ce ||
36 (currentRenderingInstance!.parent &&
37 isAsyncWrapper(currentRenderingInstance!.parent) &&
38 currentRenderingInstance!.parent.ce)
39 ) {
40 const hasProps = Object.keys(props).length > 0
41 // in custom element mode, render <slot/> as actual slot outlets
42 // wrap it with a fragment because in shadowRoot: false mode the slot
43 // element gets replaced by injected content
44 if (name !== 'default') props.name = name
45 return (
46 openBlock(),
47 createBlock(
48 Fragment,
49 null,
50 [createVNode('slot', props, fallback && fallback())],
51 hasProps ? PatchFlags.BAIL : PatchFlags.STABLE_FRAGMENT,
52 )
53 )
54 }
55
56 let slot = slots[name]
57
58 if (__DEV__ && slot && slot.length > 1) {
59 warn(
60 `SSR-optimized slot function detected in a non-SSR-optimized render ` +
61 `function. You need to mark this component with $dynamic-slots in the ` +
62 `parent template.`,
63 )
64 slot = () => []
65 }
66
67 // a compiled slot disables block tracking by default to avoid manual
68 // invocation interfering with template-based block tracking, but in
69 // `renderSlot` we can be sure that it's template-based so we can force
70 // enable it.
71 if (slot && (slot as ContextualRenderFn)._c) {
72 ;(slot as ContextualRenderFn)._d = false
73 }
74 openBlock()
75 const validSlotContent = slot && ensureValidVNode(slot(props))
76 const slotKey =
77 props.key ||
78 // slot content array of a dynamic conditional slot may have a branch
79 // key attached in the `createSlots` helper, respect that
80 (validSlotContent && (validSlotContent as any).key)
81 const rendered = createBlock(
82 Fragment,

Callers 13

renderFunction · 0.90
legacyRenderSlotFunction · 0.90
renderSlot.spec.tsFile · 0.90
testRenderFunction · 0.85
renderFunction · 0.85
scopeId.spec.tsFile · 0.85
setupFunction · 0.85
renderFunction · 0.85
hydration.spec.tsFile · 0.85
setupFunction · 0.85
renderFunction · 0.85
renderFunction · 0.85

Calls 8

isAsyncWrapperFunction · 0.90
openBlockFunction · 0.90
createBlockFunction · 0.90
warnFunction · 0.90
isSymbolFunction · 0.90
fallbackFunction · 0.85
ensureValidVNodeFunction · 0.85
slotFunction · 0.50

Tested by 9

renderFunction · 0.72
testRenderFunction · 0.68
renderFunction · 0.68
setupFunction · 0.68
renderFunction · 0.68
setupFunction · 0.68
renderFunction · 0.68
renderFunction · 0.68
renderFunction · 0.68