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) {
|
insertRootElement(rootElId: string) {
|
||||||
const template = getDOM().getDefaultDocument().createElement('template');
|
const rootElement = getDOM().getDefaultDocument().createElement('div');
|
||||||
template.innerHTML = `<div id="${rootElId}"></div>`;
|
rootElement.setAttribute('id', rootElId);
|
||||||
const rootEl = <HTMLElement>getContent(template).firstChild;
|
|
||||||
|
|
||||||
// TODO(juliemr): can/should this be optional?
|
// TODO(juliemr): can/should this be optional?
|
||||||
const oldRoots = this._doc.querySelectorAll('[id^=root]');
|
const oldRoots = this._doc.querySelectorAll('[id^=root]');
|
||||||
for (let i = 0; i < oldRoots.length; i++) {
|
for (let i = 0; i < oldRoots.length; i++) {
|
||||||
getDOM().remove(oldRoots[i]);
|
getDOM().remove(oldRoots[i]);
|
||||||
}
|
}
|
||||||
this._doc.body.appendChild(rootEl);
|
this._doc.body.appendChild(rootElement);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getContent(node: Node): Node {
|
|
||||||
if ('content' in node) {
|
|
||||||
return (<any>node).content;
|
|
||||||
} else {
|
|
||||||
return node;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue