Skip to content

Commit

Permalink
fix: using incorrect key
Browse files Browse the repository at this point in the history
  • Loading branch information
jodarove committed Apr 7, 2022
1 parent ac1ece6 commit 4438a7d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 21 deletions.
4 changes: 2 additions & 2 deletions packages/@lwc/engine-core/src/framework/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ function addVNodeToChildLWC(vnode: VCustomElement) {
}

// [st]atic node
function st(hoisted: Element, html: string, key: Key): VStatic {
function st(elmProto: Element, key: Key): VStatic {
return {
type: VNodeType.Static,
sel: undefined,
key,
elm: undefined,
elmProto: hoisted,
elmProto,
owner: getVMBeingRendered()!,
};
}
Expand Down
4 changes: 2 additions & 2 deletions packages/@lwc/engine-core/src/framework/rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ function mountStatic(vnode: VStatic, parent: ParentNode, anchor: Node | null) {
}

if (process.env.NODE_ENV !== 'production') {
const isLight = owner.renderMode === RenderMode.Light;
const isLight = renderMode === RenderMode.Light;
patchElementWithRestrictions(elm, { isPortal: false, isLight });
}

Expand Down Expand Up @@ -357,7 +357,7 @@ function observeElementChildNodes(elm: Element) {
(elm as any).$domManual$ = true;
}

export function setElementShadowToken(elm: Element, token: string) {
function setElementShadowToken(elm: Element, token: string) {
(elm as any).$shadowToken$ = token;
}

Expand Down
12 changes: 5 additions & 7 deletions packages/@lwc/engine-core/src/framework/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ export interface Template {
stylesheetToken?: string;
/** Render mode for the template. Could be light or undefined (which means it's shadow) */
renderMode?: 'light';
/** Hoisted Fragments */
hoistedFragments?: Node[];
}

export let isUpdatingTemplate: boolean = false;
Expand Down Expand Up @@ -127,21 +125,21 @@ export function parseFragment(strings: string[], ...keys: number[]): () => Eleme
const attrToken =
stylesheetToken && shadowMode === ShadowMode.Synthetic ? stylesheetToken : '""';

const genHtmlFragment: string[] = [];
const htmlFragments: string[] = [];
for (let i = 0, n = keys.length; i < n; i++) {
switch (keys[i]) {
case 0:
genHtmlFragment.push(strings[i], classToken);
htmlFragments.push(strings[i], classToken);
break;
case 1:
genHtmlFragment.push(strings[i], attrToken);
htmlFragments.push(strings[i], attrToken);
break;
}
}

genHtmlFragment.push(strings[strings.length - 1]);
htmlFragments.push(strings[strings.length - 1]);

return createFragment(genHtmlFragment.join(''));
return createFragment(htmlFragments.join(''));
};
}

Expand Down
15 changes: 6 additions & 9 deletions packages/@lwc/template-compiler/src/codegen/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { NormalizedConfig } from '../config';
import * as t from '../shared/estree';
import {
BaseElement,
BaseParentNode,
ChildNode,
Element,
Expression,
Expand All @@ -25,7 +24,6 @@ import {
isBaseElement,
isComment,
isComponent,
isIf,
isPreserveCommentsDirective,
isRenderModeDirective,
isSlot,
Expand Down Expand Up @@ -89,7 +87,7 @@ interface Scope {
function getStaticNodes(root: Root): Set<ChildNode> {
const hoistedNodes = new Set<ChildNode>();

function isStaticNode(node: BaseElement, parent: BaseParentNode): boolean {
function isStaticNode(node: BaseElement): boolean {
let result = true;
const {
name: nodeName,
Expand All @@ -100,7 +98,6 @@ function getStaticNodes(root: Root): Set<ChildNode> {
listeners,
} = node;

result &&= !isIf(parent); // when parent node is an if, this element output is bound to some component value.
result &&= !isSlot(node); // slot element can't be static.
result &&= !isComponent(node); // components are not static.

Expand All @@ -127,9 +124,9 @@ function getStaticNodes(root: Root): Set<ChildNode> {
return result;
}

function collectStaticNodes(node: ChildNode, parent: BaseParentNode) {
function collectStaticNodes(node: ChildNode) {
let childrenAreStatic = true;
let nodeIsStatic = true;
let nodeIsStatic;

if (isText(node)) {
nodeIsStatic = isLiteral(node.value);
Expand All @@ -138,12 +135,12 @@ function getStaticNodes(root: Root): Set<ChildNode> {
} else {
// it is ForBlock | If | BaseElement
node.children.forEach((childNode) => {
collectStaticNodes(childNode, node);
collectStaticNodes(childNode);

childrenAreStatic = childrenAreStatic && hoistedNodes.has(childNode);
});

nodeIsStatic = isBaseElement(node) && isStaticNode(node, parent);
nodeIsStatic = isBaseElement(node) && isStaticNode(node);
}

if (nodeIsStatic && childrenAreStatic) {
Expand All @@ -155,7 +152,7 @@ function getStaticNodes(root: Root): Set<ChildNode> {
}
}

root.children.forEach((childNode) => collectStaticNodes(childNode, root));
root.children.forEach((childNode) => collectStaticNodes(childNode));

return hoistedNodes;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LightningElement } from 'lwc';

export default class Xlink extends LightningElement {
href = "/foo";
href = '/foo';
}

0 comments on commit 4438a7d

Please sign in to comment.