Skip to content

Commit

Permalink
fix: address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ravijayaramappa committed Oct 11, 2022
1 parent 505e592 commit 4a426fe
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 18 deletions.
13 changes: 7 additions & 6 deletions packages/@lwc/engine-core/src/framework/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
isUndefined,
StringReplace,
toString,
ArrayConcat,
} from '@lwc/shared';

import { logError } from '../shared/logger';
Expand Down Expand Up @@ -193,19 +194,19 @@ function s(
if (vnode && isVScopedSlotContent(vnode)) {
const vmBeingRenderedInception = getVMBeingRendered();
let children: VNodes = [];
if (!isUndefined(slotset.owner)) {
// Evaluate in the scope of the slot content's owner
setVMBeingRendered(slotset.owner);
}
try {
if (!isUndefined(slotset.owner)) {
// Evaluate in the scope of the slot content's owner
setVMBeingRendered(slotset.owner);
}
children = vnode.factory(data.slotData);
} finally {
setVMBeingRendered(vmBeingRenderedInception);
}
return acc.concat(children);
return ArrayConcat.call(acc, children);
} else {
// If the slot content is a static list of child nodes provided by the parent, nothing to do
return acc.concat(vnode);
return ArrayConcat.call(acc, vnode);
}
}, [] as VNodes);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@lwc/engine-core/src/framework/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ function hydrateCustomElement(
vnode.elm = elm;
vnode.vm = vm;

allocateChildren(vnode, vm, owner);
allocateChildren(vnode, vm);
patchElementPropsAndAttrs(vnode, renderer);

// Insert hook section:
Expand Down
16 changes: 8 additions & 8 deletions packages/@lwc/engine-core/src/framework/rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ function mountCustomElement(
applyStyleScoping(elm, owner, renderer);

if (vm) {
allocateChildren(vnode, vm, owner);
allocateChildren(vnode, vm);
} else if (vnode.ctor !== UpgradableConstructor) {
throw new TypeError(`Incorrect Component Constructor`);
}
Expand Down Expand Up @@ -364,7 +364,7 @@ function patchCustomElement(
if (!isUndefined(vm)) {
// in fallback mode, the allocation will always set children to
// empty and delegate the real allocation to the slot elements
allocateChildren(n2, vm, vm.owner!);
allocateChildren(n2, vm);
}

// in fallback mode, the children will be always empty, so, nothing
Expand Down Expand Up @@ -559,7 +559,7 @@ function applyElementRestrictions(elm: Element, vnode: VElement | VStatic) {
}
}

export function allocateChildren(vnode: VCustomElement, vm: VM, owner: VM) {
export function allocateChildren(vnode: VCustomElement, vm: VM) {
// A component with slots will re-render because:
// 1- There is a change of the internal state.
// 2- There is a change on the external api (ex: slots)
Expand All @@ -577,7 +577,7 @@ export function allocateChildren(vnode: VCustomElement, vm: VM, owner: VM) {
const { renderMode, shadowMode } = vm;
if (shadowMode === ShadowMode.Synthetic || renderMode === RenderMode.Light) {
// slow path
allocateInSlot(vm, children, owner);
allocateInSlot(vm, children, vnode.owner);
// save the allocated children in case this vnode is reused.
vnode.aChildren = children;
// every child vnode is now allocated, and the host should receive none directly, it receives them via the shadow!
Expand Down Expand Up @@ -625,10 +625,10 @@ function allocateInSlot(vm: VM, children: VNodes, owner: VM) {
}

let slotName = '';
if (isVBaseElement(vnode) && !isUndefined(vnode.data.attrs?.slot)) {
slotName = vnode.data.attrs?.slot as string;
} else if (isVScopedSlotContent(vnode) && !isUndefined(vnode.slotName)) {
slotName = vnode.slotName;
if (isVBaseElement(vnode)) {
slotName = (vnode.data.attrs?.slot as string) ?? '';
} else if (isVScopedSlotContent(vnode)) {
slotName = vnode.slotName ?? '';
}

const vnodes: VNodes = (cmpSlotsMapping[slotName] = cmpSlotsMapping[slotName] || []);
Expand Down
2 changes: 2 additions & 0 deletions packages/@lwc/shared/src/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const {
const { isArray } = Array;

const {
concat: ArrayConcat,
copyWithin: ArrayCopyWithin,
fill: ArrayFill,
filter: ArrayFilter,
Expand Down Expand Up @@ -52,6 +53,7 @@ const {
} = String.prototype;

export {
ArrayConcat,
ArrayFilter,
ArrayFind,
ArrayFill,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"enableScopedSlots": true
"enableScopedSlots": true,
"preserveHtmlComments": true
}
4 changes: 2 additions & 2 deletions packages/@lwc/template-compiler/src/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ function parseScopedSlotContent(
parent: ParentNode,
parse5Elm: parse5.Element
): ScopedSlotContent | undefined {
const slotDataAttr = parsedAttr.pick('lwc:slot-data');
const slotDataAttr = parsedAttr.pick(ElementDirectiveName.SlotData);
if (!slotDataAttr) {
return;
}
Expand Down Expand Up @@ -1437,7 +1437,7 @@ function validateChildren(ctx: ParserCtx, element?: BaseElement, directive?: Par
// Note: An assumption here that ScopedSlotContent is the last processed directive in parseElementDirectives()
if (directive && ast.isScopedSlotContent(directive)) {
const commentOrTextChild = directive.children.find(
(child) => ast.isComment(child) || ast.isText(child)
(child) => (ctx.preserveComments && ast.isComment(child)) || ast.isText(child)
);
if (commentOrTextChild) {
ctx.throwOnNode(ParserDiagnostics.NON_ELEMENT_SCOPED_SLOT_CONTENT, commentOrTextChild);
Expand Down

0 comments on commit 4a426fe

Please sign in to comment.