close #745, keep textarea text node clean
This commit is contained in:
@@ -321,18 +321,26 @@ export function buildNodeWithSN(
|
|||||||
// close before open to make sure document was closed
|
// close before open to make sure document was closed
|
||||||
doc.close();
|
doc.close();
|
||||||
doc.open();
|
doc.open();
|
||||||
if (n.compatMode === 'BackCompat' &&
|
if (
|
||||||
(n.childNodes && n.childNodes[0].type !== NodeType.DocumentType) // there isn't one already defined
|
n.compatMode === 'BackCompat' &&
|
||||||
) {
|
n.childNodes &&
|
||||||
|
n.childNodes[0].type !== NodeType.DocumentType // there isn't one already defined
|
||||||
|
) {
|
||||||
// Trigger compatMode in the iframe
|
// Trigger compatMode in the iframe
|
||||||
// this is needed as document.createElement('iframe') otherwise inherits a CSS1Compat mode from the parent replayer environment
|
// this is needed as document.createElement('iframe') otherwise inherits a CSS1Compat mode from the parent replayer environment
|
||||||
if (n.childNodes[0].type === NodeType.Element &&
|
if (
|
||||||
'xmlns' in n.childNodes[0].attributes &&
|
n.childNodes[0].type === NodeType.Element &&
|
||||||
n.childNodes[0].attributes.xmlns === 'http://www.w3.org/1999/xhtml') {
|
'xmlns' in n.childNodes[0].attributes &&
|
||||||
|
n.childNodes[0].attributes.xmlns === 'http://www.w3.org/1999/xhtml'
|
||||||
|
) {
|
||||||
// might as well use an xhtml doctype if we've got an xhtml namespace
|
// might as well use an xhtml doctype if we've got an xhtml namespace
|
||||||
doc.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">');
|
doc.write(
|
||||||
|
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">',
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
doc.write('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "">');
|
doc.write(
|
||||||
|
'<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "">',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
node = doc;
|
node = doc;
|
||||||
|
|||||||
@@ -1428,6 +1428,21 @@ export class Replayer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
'__sn' in parent &&
|
||||||
|
parent.__sn.type === NodeType.Element &&
|
||||||
|
parent.__sn.tagName === 'textarea' &&
|
||||||
|
mutation.node.type === NodeType.Text
|
||||||
|
) {
|
||||||
|
// https://github.com/rrweb-io/rrweb/issues/745
|
||||||
|
// parent is textarea, will only keep one child node as the value
|
||||||
|
for (const c of Array.from(parent.childNodes)) {
|
||||||
|
if (c.nodeType === parent.TEXT_NODE) {
|
||||||
|
parent.removeChild(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (previous && previous.nextSibling && previous.nextSibling.parentNode) {
|
if (previous && previous.nextSibling && previous.nextSibling.parentNode) {
|
||||||
parent.insertBefore(target, previous.nextSibling);
|
parent.insertBefore(target, previous.nextSibling);
|
||||||
} else if (next && next.parentNode) {
|
} else if (next && next.parentNode) {
|
||||||
|
|||||||
Reference in New Issue
Block a user