Skip to content

Commit 2908eba

Browse files
crisbetopkozlowski-opensource
authored andcommitted
fix(platform-server): align server renderer interface with base renderer (#47868)
The `ServerRenderer` wasn't aligned with the `Renderer2` interface which meant that it was still referring to the old `debugInfo` parameters. It also wasn't implementing the `preserveContent` argument of `selectRootElement` which can lead to incosistencies between the server and the client. Fixes #47844. PR Close #47868
1 parent a8ce8f7 commit 2908eba

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

packages/platform-server/src/server_renderer.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class DefaultServerRenderer2 implements Renderer2 {
6969

7070
destroyNode = null;
7171

72-
createElement(name: string, namespace?: string, debugInfo?: any): any {
72+
createElement(name: string, namespace?: string): any {
7373
if (namespace) {
7474
const doc = this.document || getDOM().getDefaultDocument();
7575
return doc.createElementNS(NAMESPACE_URIS[namespace], name);
@@ -78,11 +78,11 @@ class DefaultServerRenderer2 implements Renderer2 {
7878
return getDOM().createElement(name, this.document);
7979
}
8080

81-
createComment(value: string, debugInfo?: any): any {
81+
createComment(value: string): any {
8282
return getDOM().getDefaultDocument().createComment(value);
8383
}
8484

85-
createText(value: string, debugInfo?: any): any {
85+
createText(value: string): any {
8686
const doc = getDOM().getDefaultDocument();
8787
return doc.createTextNode(value);
8888
}
@@ -105,18 +105,16 @@ class DefaultServerRenderer2 implements Renderer2 {
105105
}
106106
}
107107

108-
selectRootElement(selectorOrNode: string|any, debugInfo?: any): any {
109-
let el: any;
110-
if (typeof selectorOrNode === 'string') {
111-
el = this.document.querySelector(selectorOrNode);
112-
if (!el) {
113-
throw new Error(`The selector "${selectorOrNode}" did not match any elements`);
114-
}
115-
} else {
116-
el = selectorOrNode;
108+
selectRootElement(selectorOrNode: string|any, preserveContent?: boolean): any {
109+
const el = typeof selectorOrNode === 'string' ? this.document.querySelector(selectorOrNode) :
110+
selectorOrNode;
111+
if (!el) {
112+
throw new Error(`The selector "${selectorOrNode}" did not match any elements`);
117113
}
118-
while (el.firstChild) {
119-
el.removeChild(el.firstChild);
114+
if (!preserveContent) {
115+
while (el.firstChild) {
116+
el.removeChild(el.firstChild);
117+
}
120118
}
121119
return el;
122120
}
@@ -271,7 +269,7 @@ class EmulatedEncapsulationServerRenderer2 extends DefaultServerRenderer2 {
271269
}
272270

273271
override createElement(parent: any, name: string): Element {
274-
const el = super.createElement(parent, name, this.document);
272+
const el = super.createElement(parent, name);
275273
super.setAttribute(el, this.contentAttr, '');
276274
return el;
277275
}

0 commit comments

Comments
 (0)