Commit 1703670
committed
Fix template element parsing and innerHTML handling
- Fix template children being parsed into element.childNodes instead of template.content during parseHTML()
- Add special handling in parse-from-string.js to redirect template children to content DocumentFragment
- Implement proper template.innerHTML getter/setter to access content instead of direct children
- Add template.toString() method following TextElement pattern to include content in serialization
- Ensure template element follows HTML spec where innerHTML always references template.content
- Add null safety checks in parsing logic to prevent errors during template processing
The template element now correctly:
- Parses children into content during HTML parsing
- Returns content innerHTML when accessing template.innerHTML
- Maintains separation between direct children and content
- Serializes with content included in toString()
--browser result--
const f = document.createDocumentFragment();
const d = document.createElement('div')
d.innerHTML='<a>aaa</a>';
f.append(d);
const t = document.createElement('template');
t.content.append(f);
console.log(t.innerHTML); // '<div><a>aaa</a></div>'
console.log(t.innerText); //''
--linkedom--
console.log(t.innerHTML); // ''
console.log(t.innerText); //''1 parent 44b646e commit 1703670
File tree
2 files changed
+0
-2
lines changed2 files changed
+0
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
114 | | - | |
115 | 114 | | |
116 | 115 | | |
117 | 116 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
113 | 112 | | |
114 | 113 | | |
115 | 114 | | |
| |||
0 commit comments