diff --git a/packages/@lwc/engine-core/src/framework/rendering.ts b/packages/@lwc/engine-core/src/framework/rendering.ts
index e3813fd0b4..c6ad12bd29 100644
--- a/packages/@lwc/engine-core/src/framework/rendering.ts
+++ b/packages/@lwc/engine-core/src/framework/rendering.ts
@@ -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;
@@ -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);
@@ -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);
@@ -245,7 +245,7 @@ function mountStatic(
patchElementWithRestrictions(elm, { isPortal: false, isLight });
}
- insertNode(elm, parent, anchor);
+ insertNode(elm, parent, anchor, renderer);
}
function mountCustomElement(
diff --git a/packages/@lwc/engine-core/src/framework/template.ts b/packages/@lwc/engine-core/src/framework/template.ts
index 8e7b7cf91c..f255ead217 100644
--- a/packages/@lwc/engine-core/src/framework/template.ts
+++ b/packages/@lwc/engine-core/src/framework/template.ts
@@ -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,
@@ -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;
@@ -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);
@@ -129,6 +129,7 @@ function buildParseFragmentFn(
const {
context: { hasScopedStyles, stylesheetToken },
shadowMode,
+ renderer,
} = getVMBeingRendered()!;
const hasStyleToken = !isUndefined(stylesheetToken);
const isSyntheticShadow = shadowMode === ShadowMode.Synthetic;
@@ -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('');
+// 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('');
return getFirstChild(fragment);
});
diff --git a/packages/@lwc/engine-server/src/index.ts b/packages/@lwc/engine-server/src/index.ts
index 2456635f70..0243c91203 100644
--- a/packages/@lwc/engine-server/src/index.ts
+++ b/packages/@lwc/engine-server/src/index.ts
@@ -26,6 +26,8 @@ export {
setHooks,
getComponentDef,
isComponentConstructor,
+ parseFragment,
+ parseFragment as parseSVGFragment,
} from '@lwc/engine-core';
// Engine-server public APIs -----------------------------------------------------------------------