Skip to content

Commit

Permalink
fix(engine): to get the rebase done for PR 2781
Browse files Browse the repository at this point in the history
  • Loading branch information
caridy authored and nolanlawson committed Jun 7, 2022
1 parent 454fd74 commit ec12fce
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
8 changes: 4 additions & 4 deletions packages/@lwc/engine-core/src/framework/rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function patch(n1: VNode, n2: VNode, renderer: RendererAPI) {
case VNodeType.Static:
n2.elm = n1.elm;
break;

case VNodeType.Element:
patchElement(n1 as VElement, n2, n2.data.renderer ?? renderer);
break;
Expand All @@ -130,7 +130,7 @@ export function mount(node: VNode, parent: ParentNode, renderer: RendererAPI, an
// VStatic cannot have a custom renderer associated to them, using owner's renderer
mountStatic(node, parent, anchor, renderer);
break;

case VNodeType.Element:
// If the vnode data has a renderer override use it, else fallback to owner's renderer
mountElement(node, parent, anchor, node.data.renderer ?? renderer);
Expand Down Expand Up @@ -226,7 +226,7 @@ function mountStatic(
renderer: RendererAPI
) {
const { owner } = vnode;
const { cloneNode, isSyntheticShadowDefined, insertNode } = renderer;
const { cloneNode, isSyntheticShadowDefined } = renderer;
const elm = (vnode.elm = cloneNode(vnode.fragment, true));

linkNodeToShadow(elm, owner, renderer);
Expand All @@ -245,7 +245,7 @@ function mountStatic(
patchElementWithRestrictions(elm, { isPortal: false, isLight });
}

insertNode(elm, parent, anchor);
insertNode(elm, parent, anchor, renderer);
}

function mountCustomElement(
Expand Down
19 changes: 12 additions & 7 deletions packages/@lwc/engine-core/src/framework/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {

import { logError } from '../shared/logger';
import { getComponentTag } from '../shared/format';
import { createFragment, getFirstChild } from '../renderer';
import api, { RenderAPI } from './api';
import {
RenderMode,
Expand All @@ -42,6 +41,7 @@ import {
import { logOperationEnd, logOperationStart, OperationId } from './profiler';
import { getTemplateOrSwappedTemplate, setActiveVM } from './hot-swaps';
import { VNodes } from './vnodes';
import { RendererAPI } from './renderer';

export interface Template {
(api: RenderAPI, cmp: object, slotSet: SlotSet, cache: TemplateCache): VNodes;
Expand Down Expand Up @@ -120,7 +120,7 @@ const enum FragmentCache {
}

function buildParseFragmentFn(
createFragmentFn: (html: string) => Element
createFragmentFn: (html: string, renderer: RendererAPI) => Element
): (strings: string[], ...keys: number[]) => () => Element {
return (strings: string[], ...keys: number[]) => {
const cache = create(null);
Expand All @@ -129,6 +129,7 @@ function buildParseFragmentFn(
const {
context: { hasScopedStyles, stylesheetToken },
shadowMode,
renderer,
} = getVMBeingRendered()!;
const hasStyleToken = !isUndefined(stylesheetToken);
const isSyntheticShadow = shadowMode === ShadowMode.Synthetic;
Expand Down Expand Up @@ -170,18 +171,22 @@ function buildParseFragmentFn(

htmlFragment += strings[strings.length - 1];

cache[cacheKey] = createFragmentFn(htmlFragment);
cache[cacheKey] = createFragmentFn(htmlFragment, renderer);

return cache[cacheKey];
};
};
}

// Note: at the moment this code executes, createFragment have not being set.
export const parseFragment = buildParseFragmentFn((html) => createFragment(html));
export const parseSVGFragment = buildParseFragmentFn((html) => {
const fragment = createFragment('<svg>' + html + '</svg>');
// Note: at the moment this code executes, we don't have a renderer yet.
export const parseFragment = buildParseFragmentFn((html, renderer) => {
const { createFragment } = renderer;
return createFragment(html);
});

export const parseSVGFragment = buildParseFragmentFn((html, renderer) => {
const { createFragment, getFirstChild } = renderer;
const fragment = createFragment('<svg>' + html + '</svg>');
return getFirstChild(fragment);
});

Expand Down
2 changes: 2 additions & 0 deletions packages/@lwc/engine-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export {
setHooks,
getComponentDef,
isComponentConstructor,
parseFragment,
parseFragment as parseSVGFragment,
} from '@lwc/engine-core';

// Engine-server public APIs -----------------------------------------------------------------------
Expand Down

0 comments on commit ec12fce

Please sign in to comment.