a post-component library for building user-interfaces on the web.

fix a list handling bug (#30)

* add failing test

* fix bug

authored by tombl.dev and committed by

GitHub b4f84a79 6cd41a92

+17 -3
+4 -3
src/html.js
··· 489 489 490 490 // create or update a root for every item. 491 491 let i = 0 492 + let end = this.#span._start 492 493 for (const item of value) { 493 494 // @ts-expect-error -- WeakMap lookups of non-objects always return undefined, which is fine 494 495 const key = keys.get(item) ?? item 495 - let root = (this.#roots[i] ??= Root.insertAfter(this.#span._end)) 496 + let root = (this.#roots[i] ??= Root.insertAfter(end)) 496 497 497 498 if (key !== undefined && root._key !== key) { 498 499 const j = this.#roots.findIndex(r => r._key === key) ··· 518 519 } 519 520 520 521 root.render(item) 521 - this.#span._end = root._span._end 522 - 522 + end = root._span._end 523 523 i++ 524 524 } 525 525 ··· 531 531 root._span._deleteContents() 532 532 } 533 533 534 + this.#span._end = end 534 535 if (endsWereEqual) this.#parentSpan._end = this.#span._end 535 536 536 537 return
+13
test/lists.test.ts
··· 148 148 root.render(wrapped) 149 149 expect(el.innerHTML).toBe('[]') 150 150 }) 151 + 152 + it('full then empty then full', () => { 153 + const { root, el } = setup() 154 + 155 + root.render([1]) 156 + expect(el.innerHTML).toBe('1') 157 + 158 + root.render([]) 159 + expect(el.innerHTML).toBe('') 160 + 161 + root.render([2]) 162 + expect(el.innerHTML).toBe('2') 163 + }) 151 164 }) 152 165 153 166 describe('list reordering', () => {