Parse and serialize template content in HTML output - #686
olavoasantos wants to merge 1 commit into
Conversation
ea10745 to
83a8503
Compare
83a8503 to
27f275e
Compare
|
The template-content routing and iterative serializer look good. One narrow completion before landing: lazy empty template content still falls back to the element's ordinary children. At const template = document.createElement('template');
template.appendChild(document.createElement('span')).textContent = 'ordinary';
template.outerHTML;
// Head: '<template><span>ordinary</span></template>'
void template.content;
template.outerHTML;
// Head: '<template></template>'Native returns The incorrect initial output is inherited from base; the new implementation makes it switch after a getter read. This is an incomplete branch of the template fix, not a newly introduced loss of valid content. Please select actual HTML templates by namespace and exact localName, then treat absent content as empty without allocating it. Keep ordinary-child serialization for ordinary elements, foreign/null-namespace elements named Focused regression coverage:
A build-only candidate for this selection changes exactly four lazy-template results to native behavior in a 167-case matrix; the other 163 results stay unchanged. No production source fix or full candidate suite performed. Separately, this PR already implements the foreign-namespace portion of the #685 correction. Reuse that guard when correcting/restacking #685 rather than adding another implementation. The remaining established-name/case and entity issues stay with #685; closing-tag/SVG parsing stays with #687. Validation at |
27f275e to
ceebf52
Compare
ceebf52 to
2f9bb05
Compare
2f9bb05 to
ecd3b1e
Compare
ecd3b1e to
0a39389
Compare
|
Agreed. The coverage includes lazy, initialized-empty, populated, cleared, and prefixed HTML templates; foreign/null-namespace and established-case |
Problem
HTMLTemplateElementstores its implemented contents intemplate.content, not in the template element's ordinary child list. Serialization walked only ordinary children, soouterHTMLomitted populated template content. In addition, parsing a<template>nested in ordinary HTML placed its descendants in that ordinary child list instead of the template content fragment.Impact
Minor. Template markup assigned through the exposed
innerHTMLpath could vanish fromouterHTML, while parsed nested templates could have the wrong tree shape. Consumers that pass serialized templates through Remote DOM therefore lose or misrepresent implemented template content.Reproduction
Before this change, the final expression returned
<template></template>because serialization did not visittemplate.content. It now returns<template><p class="message">Hello</p></template>.Change
<template>start and end tags into the template's content fragment, restoring the outer insertion target when the template closes.<br></br>.Tests
Adds
packages/polyfill/source/tests/serialization-template.test.ts, covering empty, populated, nested, and reentrantly parsed templates; restoration of surrounding insertion targets; escaping, comments, and void elements inside template content; the HTML-versus-SVG void distinction; and constructed and parsed 6,000-level template serialization with explicit 20-second budgets.Stack
preserve-html-parser-dataThe restacked layer accepts nullable
NamespaceURIvalues and gives both 6,000-deep serialization tests explicit timeout budgets.Validation
Fresh GitHub CI on restacked head
27f275epasses: