Skip to content

Commit

Permalink
Remove impossible branch (#4491)
Browse files Browse the repository at this point in the history
* Remove impossible branch

* Bail a bit later

* Leverage .some
  • Loading branch information
JoviDeCroock authored Sep 13, 2024
1 parent 022dbb1 commit 0943ac7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
9 changes: 4 additions & 5 deletions src/diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export function diff(

newVNode._dom = oldVNode._dom;
newVNode._children = oldVNode._children;
newVNode._children.forEach(vnode => {
newVNode._children.some(vnode => {
if (vnode) vnode._parent = newVNode;
});

Expand Down Expand Up @@ -455,7 +455,7 @@ function diffElementNodes(
if (i == 'children') {
} else if (i == 'dangerouslySetInnerHTML') {
oldHtml = value;
} else if (i !== 'key' && !(i in newProps)) {
} else if (!(i in newProps)) {
if (
(i == 'value' && 'defaultValue' in newProps) ||
(i == 'checked' && 'defaultChecked' in newProps)
Expand All @@ -479,7 +479,6 @@ function diffElementNodes(
} else if (i == 'checked') {
checked = value;
} else if (
i !== 'key' &&
(!isHydrating || typeof value == 'function') &&
oldProps[i] !== value
) {
Expand Down Expand Up @@ -524,7 +523,7 @@ function diffElementNodes(
// Remove children that are not part of any vnode.
if (excessDomChildren != null) {
for (i = excessDomChildren.length; i--; ) {
if (excessDomChildren[i] != null) removeNode(excessDomChildren[i]);
removeNode(excessDomChildren[i]);
}
}
}
Expand Down Expand Up @@ -626,7 +625,7 @@ export function unmount(vnode, parentVNode, skipRemove) {
}
}

if (!skipRemove && vnode._dom != null) {
if (!skipRemove) {
removeNode(vnode._dom);
}

Expand Down
3 changes: 1 addition & 2 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ export function assign(obj, props) {
* @param {preact.ContainerNode} node The node to remove
*/
export function removeNode(node) {
let parentNode = node.parentNode;
if (parentNode) parentNode.removeChild(node);
if (node && node.parentNode) node.parentNode.removeChild(node);
}

export const slice = EMPTY_ARR.slice;

0 comments on commit 0943ac7

Please sign in to comment.