Skip to content

Commit d2ad2db

Browse files
committed
fix #43; handle empty insert
1 parent 21fcad3 commit d2ad2db

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

public/client.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,13 @@ export function open({hash} = {}) {
147147
switch (item.type) {
148148
case "html":
149149
if (root.children.length === 0) {
150-
var template = document.createElement("template");
151-
template.innerHTML = item.html;
152-
root.appendChild(template.content.firstChild);
153-
}
154-
if (newPos >= root.children.length) {
155-
root.children[root.children.length - 1].insertAdjacentHTML("afterend", item.html);
156-
newPos++;
150+
root.insertAdjacentHTML("beforeend", item.html);
151+
} else if (newPos < root.children.length) {
152+
root.children[newPos].insertAdjacentHTML("beforebegin", item.html);
157153
} else {
158-
root.children[newPos++].insertAdjacentHTML("beforebegin", item.html);
154+
root.lastElementChild.insertAdjacentHTML("afterend", item.html);
159155
}
156+
++newPos;
160157
item.cellIds.forEach((id) => {
161158
const cell = cellsById.get(id);
162159
if (cell) define(cell.cell);

0 commit comments

Comments
 (0)