Skip to content

Commit

Permalink
Fix child node updating
Browse files Browse the repository at this point in the history
  • Loading branch information
mhluska committed May 28, 2022
1 parent 77e818a commit a436c98
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,13 @@ export const reconcile = (
const prevNodeChild = prevNode.children[index];
const newNodeChild = newNode.children[index];

const prevExists =
prevNodeChild && isVirtualFunctionElement(prevNodeChild)
? !!prevNodeChild.result
: !!prevNodeChild;

const newExists = !!newNodeChild;

// There are a few cases to consider when child nodes are updated:
//
// 1. DOM node does not exist:
Expand All @@ -286,17 +293,17 @@ export const reconcile = (
// list? That is handled by case 1a where a DOM node does not exist.

if (domNodeChild) {
if (prevNodeChild && newNodeChild) {
if (prevExists && newExists) {
reconcile(domNodeChild, prevNodeChild, newNodeChild);
} else if (prevNodeChild) {
} else if (prevExists) {
domNodeChild.remove();
} else if (newNodeChild) {
} else if (newExists) {
insertBefore(createDomNode(newNodeChild), domNodeChild);
continue;
} else {
continue;
}
} else if (newNodeChild) {
} else if (newExists) {
appendNode(domNode, createDomNode(newNodeChild));
}

Expand Down

0 comments on commit a436c98

Please sign in to comment.