Skip to content

Commit

Permalink
jsxy: Correctly handle removing multiple children with nulls
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasfasching committed Mar 8, 2024
1 parent fa02d17 commit f9d20d9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/jsxy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ function renderChildren(parentNode, vnodes, component, ns) {
for (let k in oldHooks) {
if (!(k in newHooks)) for (let h of oldHooks[k]) h.unmount?.();
}
for (let n = parentNode.childNodes.length - vnodes.length; n > 0; n--) {
unmount(parentNode.lastChild).remove();
for (let i = nodes.length-1; i >= vnodes.length; i--) {
unmount(nodes[i]).remove()
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/jsxy.mjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,5 +248,7 @@
"jsxy: render: render root/app from any child (1)": "<div><button></button>1</div>",
"jsxy: render: renderChildren works correctly when removing children (0)": "<div>123</div>",
"jsxy: render: renderChildren works correctly when removing children (1)": "<div>13</div>",
"jsxy: render: renderChildren works correctly when removing multiple children (0)": "<div>123</div>",
"jsxy: render: renderChildren works correctly when removing multiple children (1)": "<div>3</div>",
"jsxy: render: render removes existing vnode props when necessary (0)": "<div class=\"\">hello world</div>"
}
9 changes: 8 additions & 1 deletion test/jsxy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,18 @@ t.describe("jsxy", () => {
t.assertFixture(document.body.innerHTML);
});

t("renderChildren works correctly when removing multiple children", () => {
render(html`<div>${[1, 2, 3]}</div>`, document.body);
t.assertFixture(document.body.innerHTML);
render(html`<div>${[null, 3]}</div>`, document.body);
t.assertFixture(document.body.innerHTML);
});

t("render removes existing vnode props when necessary", () => {
render(html`<div .class>hello world</div>`, document.body);
render(html`<div>hello world</div>`, document.body);
t.assertFixture(document.body.innerHTML);
})
});
});

t.describe("db/query", () => {
Expand Down

0 comments on commit f9d20d9

Please sign in to comment.