Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Helvik committed Oct 27, 2019
1 parent 6dcc28d commit 99ea173
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adrianhelvik/fragdom",
"version": "2.1.9",
"version": "2.1.10",
"main": "dist/index.js",
"module": "src/index.js",
"license": "MIT",
Expand Down
6 changes: 3 additions & 3 deletions src/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ class Element extends Node {
for (const c of child) {
if (realNode.childNodes[index] !== c) {
if (realNode.childNodes[index]) {
realNode.removeChild(realNode.childNodes[index])
realNode.replaceChild(c, realNode.childNodes[index])
} else {
realNode.appendChild(c)
}

realNode.appendChild(c)
}
index += 1
}
Expand Down
22 changes: 20 additions & 2 deletions src/Element.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,6 @@ describe('.replaceChild(newChild, oldChild)', () => {

template.reconcile()

window.DEBUG = true

template.replaceChild(
fragdom.createElement('new-b'),
template.childNodes[1],
Expand All @@ -325,4 +323,24 @@ describe('.replaceChild(newChild, oldChild)', () => {

expect(template.realNode.innerHTML).toBe('<a></a><new-b></new-b><c></c>')
})

test('reconciliation bugfix', () => {
const root = <div />

const frag = (
<>
{'1'}
{''}
{'2'}
</>
)

root.appendChild(frag)
frag.reconcile()

frag.replaceChild(fragdom.createTextNode('Hello'), frag.childNodes[1])
frag.reconcile()

expect(root.realNode.innerHTML).toBe('1Hello2')
})
})
5 changes: 5 additions & 0 deletions src/Fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class Fragment extends Node {
this.markAsDirty()
}

replaceChild(newChild, oldChild) {
super.replaceChild(newChild, oldChild)
this.markAsDirty()
}

dirty() {
return this.#dirty
}
Expand Down

0 comments on commit 99ea173

Please sign in to comment.