Skip to content

Commit 1703670

Browse files
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 changed

2 files changed

+0
-2
lines changed

cjs/shared/parse-from-string.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ const parseFromString = (document, isHTML, markupLanguage) => {
111111
onclosetag() {
112112
if (isHTML && node === ownerSVGElement)
113113
ownerSVGElement = null;
114-
// template content인 경우 원래 template로 돌아가기
115114
if (node && node[PRIVATE]) {
116115
node = node[PRIVATE];
117116
}

esm/shared/parse-from-string.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ export const parseFromString = (document, isHTML, markupLanguage) => {
109109
onclosetag() {
110110
if (isHTML && node === ownerSVGElement)
111111
ownerSVGElement = null;
112-
// template content인 경우 원래 template로 돌아가기
113112
if (node && node[PRIVATE]) {
114113
node = node[PRIVATE];
115114
}

0 commit comments

Comments
 (0)