Better treatment of invalid HtmlFragments

This commit is contained in:
Tony Garnock-Jones 2024-04-17 13:23:50 +02:00
parent 305c0c26ee
commit 80250fdac9
1 changed files with 16 additions and 1 deletions

View File

@ -70,7 +70,22 @@ function nodeInserter(n: number): PlaceholderAction {
switch (typeof f) {
case 'string': newNode = document.createTextNode(f); break;
case 'number': newNode = document.createTextNode('' + f); break;
default: newNode = f; break;
case 'object':
if (f !== null && 'nodeType' in f) {
newNode = f;
break;
}
/* fall through */
default: {
let info;
try {
info = '' + f;
} catch (_e) {
info = (f as any).toString();
}
newNode = document.createTextNode(`<ERROR: invalid HtmlFragment: ${info}>`);
break;
}
}
node.parentNode?.insertBefore(newNode, node);
}