diff --git a/package.json b/package.json index c123193..fa21951 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@adrianhelvik/fragdom", - "version": "2.1.11", + "version": "2.1.12", "main": "dist/index.js", "module": "src/index.js", "license": "MIT", diff --git a/src/Element.js b/src/Element.js index dbc0c42..7653ada 100644 --- a/src/Element.js +++ b/src/Element.js @@ -125,7 +125,6 @@ class Element extends Node { } } - let completeAt = this.childNodes.length let index = 0 for (let i = 0; i < this.childNodes.length; i++) { @@ -133,7 +132,6 @@ class Element extends Node { const child = this.childNodes[i].realNode if (Array.isArray(child)) { - completeAt += child.length for (const c of child) { if (realNode.childNodes[index] !== c) { if (realNode.childNodes[index]) { @@ -156,11 +154,7 @@ class Element extends Node { } } - for ( - let i = realNode.childNodes.length - 1; - i >= 0 && i >= completeAt; - i-- - ) { + for (let i = realNode.childNodes.length - 1; i >= 0 && i >= index; i--) { realNode.removeChild(realNode.childNodes[i]) } diff --git a/src/spec.js b/src/spec.js index 630a124..e1e1e02 100644 --- a/src/spec.js +++ b/src/spec.js @@ -82,7 +82,7 @@ test('another bugfix', () => { expect(root.realNode.innerHTML).toBe('') }) -test('bugfix adjacent fragments', () => { +test('bugfix: adjacent fragments', () => { const root =
root.appendChild( @@ -110,7 +110,7 @@ test('bugfix adjacent fragments', () => { expect(root.realNode.innerHTML).toBe('Hello123') }) -test('bugfix fragment with element with text not updating', () => { +test('bugfix: fragment with element with text not updating', () => { const root =
root.reconcile() @@ -132,3 +132,16 @@ test('bugfix fragment with element with text not updating', () => { expect(root.realNode.innerHTML).toBe('
Hi "b"
') }) + +test('bugfix: replace text node with empty fragment', () => { + const root =
Hello
+ root.reconcile() + root.replaceChild(<>, root.childNodes[0]) + root.reconcile() + expect(root.debug().split('\n')).toEqual([ + '
' /********************************/, + ' <>', + '
', + ]) + expect(root.realNode.outerHTML).toBe('
') +})