switch to comments as placeholder nodes (#2579)

This commit is contained in:
Evan Almloff authored and GitHub committed 2024-07-02 15:31:18 -07:00
1 parent 30f6986283
commit 4cab834640
8 files changed
+29 -24

No files matched your search

+20 -11
View File
@@ -173,9 +173,22 @@ export class BaseInterpreter {
const currentNode = treeWalker.currentNode as ChildNode;
if (currentNode.nodeType === Node.COMMENT_NODE) {
const id = currentNode.textContent!;
const split = id.split("node-id");
if (split.length > 1) {
// First try to hydrate the comment node as a placeholder
const placeholderSplit = id.split("placeholder");
if (placeholderSplit.length > 1) {
this.nodes[ids[parseInt(placeholderSplit[1])]] = currentNode;
if (!treeWalker.nextNode()) {
break;
}
continue;
}
// Then try to hydrate the comment node as a marker for the next text node
const textNodeSplit = id.split("node-id");
if (textNodeSplit.length > 1) {
// For most text nodes, this should be text
let next = currentNode.nextSibling;
// remove the comment node
@@ -198,23 +211,19 @@ export class BaseInterpreter {
commentAfterText = textNode.nextSibling;
}
treeWalker.currentNode = commentAfterText;
this.nodes[ids[parseInt(split[1])]] = textNode;
this.nodes[ids[parseInt(textNodeSplit[1])]] = textNode;
let exit = !treeWalker.nextNode();
// remove the comment node after the text node
commentAfterText.remove();
if (exit) {
break;
}
} else {
if (!treeWalker.nextNode()) {
break;
}
}
} else {
if (!treeWalker.nextNode()) {
break;
continue;
}
}
if (!treeWalker.nextNode()) {
break;
}
}
}
}