Skip to content

Commit

Permalink
fix(platform-server): align server renderer interface with base rende…
Browse files Browse the repository at this point in the history
…rer (#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
  • Loading branch information
crisbeto authored and pkozlowski-opensource committed Oct 25, 2022
1 parent a8ce8f7 commit 2908eba
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions packages/platform-server/src/server_renderer.ts
Expand Up @@ -69,7 +69,7 @@ class DefaultServerRenderer2 implements Renderer2 {

destroyNode = null;

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

createComment(value: string, debugInfo?: any): any {
createComment(value: string): any {
return getDOM().getDefaultDocument().createComment(value);
}

createText(value: string, debugInfo?: any): any {
createText(value: string): any {
const doc = getDOM().getDefaultDocument();
return doc.createTextNode(value);
}
Expand All @@ -105,18 +105,16 @@ class DefaultServerRenderer2 implements Renderer2 {
}
}

selectRootElement(selectorOrNode: string|any, debugInfo?: any): any {
let el: any;
if (typeof selectorOrNode === 'string') {
el = this.document.querySelector(selectorOrNode);
if (!el) {
throw new Error(`The selector "${selectorOrNode}" did not match any elements`);
}
} else {
el = selectorOrNode;
selectRootElement(selectorOrNode: string|any, preserveContent?: boolean): any {
const el = typeof selectorOrNode === 'string' ? this.document.querySelector(selectorOrNode) :
selectorOrNode;
if (!el) {
throw new Error(`The selector "${selectorOrNode}" did not match any elements`);
}
while (el.firstChild) {
el.removeChild(el.firstChild);
if (!preserveContent) {
while (el.firstChild) {
el.removeChild(el.firstChild);
}
}
return el;
}
Expand Down Expand Up @@ -271,7 +269,7 @@ class EmulatedEncapsulationServerRenderer2 extends DefaultServerRenderer2 {
}

override createElement(parent: any, name: string): Element {
const el = super.createElement(parent, name, this.document);
const el = super.createElement(parent, name);
super.setAttribute(el, this.contentAttr, '');
return el;
}
Expand Down

0 comments on commit 2908eba

Please sign in to comment.