Skip to content

Commit

Permalink
refactor: reuse mountElement to render slot element
Browse files Browse the repository at this point in the history
  • Loading branch information
jodarove committed Feb 25, 2022
1 parent 366c2a3 commit e8a7ea7
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions packages/@lwc/engine-core/src/framework/rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,7 @@ function mount(node: VNode, parent: ParentNode, anchor: Node | null, vm: VM) {
}

function mountSlot(vnode: VSlot, parent: ParentNode, anchor: Node | null, vm: VM) {
const {
sel,
data: { svg },
aChildren,
} = vnode;
const { aChildren } = vnode;

// weather to render the slotted content or the default slot content.
const children: VNodes = aChildren ? aChildren.vnodes : vnode.children;
Expand All @@ -161,20 +157,18 @@ function mountSlot(vnode: VSlot, parent: ParentNode, anchor: Node | null, vm: VM
return;
}

const namespace = isTrue(svg) ? SVG_NAMESPACE : undefined;
const elm = createElement(sel, namespace);
linkNodeToShadow(elm, vm); // the slot element is part of vm
const elementVNode = {
...vnode,
type: VNodeType.Element,
children: [],
aChildren: undefined,
};
mountElement(elementVNode as VElement, parent, anchor, vm);

// let's render the slot as an element.
// @todo: alternatively vnode as unknown as VElement
fallbackElmHook(elm, { ...vnode, type: VNodeType.Element }, vm); // the slot element is part of vm
vnode.elm = elm;

patchElementPropsAndAttrs(null, vnode);

insertNode(elm, parent, anchor);
vnode.elm = elementVNode.elm!;

mountVNodes(children, elm, null, 0, children.length, slottedContentOwnerVM);
// swap the owner vm when mounting the children.
mountVNodes(children, vnode.elm, null, 0, children.length, slottedContentOwnerVM);
}

function patchText(n1: VText, n2: VText) {
Expand Down

0 comments on commit e8a7ea7

Please sign in to comment.