replace script tag with noscript and inline the states of form field components

This commit is contained in:
Yanzhen Yu
2018-09-30 17:38:44 +08:00
parent 7d1cf13266
commit 05e4103f7a
6 changed files with 195 additions and 75 deletions

View File

@@ -11,11 +11,20 @@ function buildNode(n: serializedNodeWithId): Node | null {
n.systemId,
);
case NodeType.Element:
const node = document.createElement(n.tagName);
const tagName = n.tagName === 'script' ? 'noscript' : n.tagName;
const node = document.createElement(tagName);
for (const name in n.attributes) {
if (n.attributes.hasOwnProperty(name)) {
let value = n.attributes[name];
value = typeof value === 'boolean' ? '' : value;
// textarea hack
if (n.tagName === 'textarea' && name === 'value') {
const child = document.createTextNode(value);
node.appendChild(child);
continue;
}
try {
node.setAttribute(name, n.attributes[name]);
node.setAttribute(name, value);
} catch (error) {
// skip invalid attribute
}