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:
parent
32dd3c5dd1
commit
8c062493a0
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue