This repository was archived by the owner on Jan 9, 2025. It is now read-only.
Commit e865f63
committed
fix(html): Allow for nested text nodes in iterables
This changes the API from `children` to `childNodes` because `children`
does not include `Text` nodes.
diff --git src/html.ts src/html.ts
index d0578b1..6fe4502 100644
--- src/html.ts
+++ src/html.ts
@@ -19,7 +19,7 @@ function processSubTemplate(part: TemplatePart, value: unknown): boolean {
function processDocumentFragment(part: TemplatePart, value: unknown): boolean {
if (value instanceof DocumentFragment && part instanceof NodeTemplatePart) {
- part.replace((value as unknown) as ChildNode)
+ if (value.childNodes.length) part.replace(...value.childNodes)
return true
}
return false
diff --git test/html.ts test/html.ts
index 6dbfc6c..0ff3ee2 100644
--- test/html.ts
+++ test/html.ts
@@ -40,6 +40,17 @@ describe('render', () => {
render(main(child('Goodbye')), surface)
expect(surface.innerHTML).to.equal('<div><span>Goodbye</span></div>')
})
+
+ it('can nest document fragments and text nodes', () => {
+ const main = frag => html`<span>${frag}</span>`
+ const fragment = document.createDocumentFragment()
+ fragment.append(new Text('Hello World'))
+ render(main(fragment), surface)
+ expect(surface.innerHTML).to.equal('<span>Hello World</span>')
+ fragment.append(document.createTextNode('Hello Universe!'))
+ render(main(fragment), surface)
+ expect(surface.innerHTML).to.equal('<span>Hello Universe!</span>')
+ })
})
describe('iterables', () => {1 parent 00a735f commit e865f63
2 files changed
+30
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
65 | 93 | | |
66 | 94 | | |
67 | 95 | | |
| |||
0 commit comments