Skip to content

Commit a32cde2

Browse files
committed
Fix regression
1 parent 922fc06 commit a32cde2

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/morphlex.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,9 @@ class Morph {
280280
this.#morphOneToOne(from, to[0]!)
281281
} else {
282282
const newNodes = [...to]
283-
this.#morphOneToOne(from, newNodes.shift()!)
284283
const insertionPoint = from.nextSibling
285284
const parent = from.parentNode
285+
this.#morphOneToOne(from, newNodes.shift()!)
286286

287287
if (!parent) {
288288
for (let i = 0; i < newNodes.length; i++) {

test/morphlex-uncovered.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,25 @@ describe("Morphlex - Remaining Uncovered Lines", () => {
220220
parent.remove()
221221
})
222222

223+
it("should keep trailing nodes when the first one-to-many morph replaces the source node", () => {
224+
const parent = document.createElement("div")
225+
const single = document.createElement("span")
226+
single.id = "single"
227+
single.textContent = "Single"
228+
parent.appendChild(single)
229+
document.body.appendChild(parent)
230+
231+
morph(single, "<div id='first'>First</div><em id='second'>Second</em>")
232+
233+
expect(parent.children.length).toBe(2)
234+
expect(parent.children[0]?.tagName).toBe("DIV")
235+
expect(parent.children[0]?.id).toBe("first")
236+
expect(parent.children[1]?.tagName).toBe("EM")
237+
expect(parent.children[1]?.id).toBe("second")
238+
239+
parent.remove()
240+
})
241+
223242
it("should call callbacks when morphing one to many", () => {
224243
const parent = document.createElement("div")
225244
const single = document.createElement("span")

0 commit comments

Comments
 (0)