refactor(core): don't use innerHTML in DOMTestComponentRenderer (#41099)

The use of innerHTML is unnecessary and causes TrustedType violations.

PR Close #41099
This commit is contained in:
Igor Minar 2021-03-05 20:02:21 -08:00 committed by Andrew Kushnir
parent 32dd3c5dd1
commit 8c062493a0
1 changed files with 3 additions and 12 deletions

View File

@ -20,23 +20,14 @@ export class DOMTestComponentRenderer extends TestComponentRenderer {
}
insertRootElement(rootElId: string) {
const template = getDOM().getDefaultDocument().createElement('template');
template.innerHTML = `<div id="${rootElId}"></div>`;
const rootEl = <HTMLElement>getContent(template).firstChild;
const rootElement = getDOM().getDefaultDocument().createElement('div');
rootElement.setAttribute('id', rootElId);
// TODO(juliemr): can/should this be optional?
const oldRoots = this._doc.querySelectorAll('[id^=root]');
for (let i = 0; i < oldRoots.length; i++) {
getDOM().remove(oldRoots[i]);
}
this._doc.body.appendChild(rootEl);
}
}
function getContent(node: Node): Node {
if ('content' in node) {
return (<any>node).content;
} else {
return node;
this._doc.body.appendChild(rootElement);
}
}