File tree Expand file tree Collapse file tree 3 files changed +19
-5
lines changed
test/runtime/samples/template Expand file tree Collapse file tree 3 files changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -698,7 +698,7 @@ export class HtmlTag {
698
698
// html tag nodes
699
699
n : ChildNode [ ] ;
700
700
// target
701
- t : HTMLElement | SVGElement ;
701
+ t : HTMLElement | SVGElement | DocumentFragment ;
702
702
// anchor
703
703
a : HTMLElement | SVGElement ;
704
704
@@ -718,8 +718,9 @@ export class HtmlTag {
718
718
) {
719
719
if ( ! this . e ) {
720
720
if ( this . is_svg ) this . e = svg_element ( target . nodeName as keyof SVGElementTagNameMap ) ;
721
- else this . e = element ( target . nodeName as keyof HTMLElementTagNameMap ) ;
722
- this . t = target ;
721
+ /** #7364 target for <template> may be provided as #document-fragment(11) */
722
+ else this . e = element ( ( target . nodeType === 11 ? 'TEMPLATE' : target . nodeName ) as keyof HTMLElementTagNameMap ) ;
723
+ this . t = target . tagName !== 'TEMPLATE' ? target : ( target as HTMLTemplateElement ) . content ;
723
724
this . c ( html ) ;
724
725
}
725
726
@@ -728,7 +729,7 @@ export class HtmlTag {
728
729
729
730
h ( html : string ) {
730
731
this . e . innerHTML = html ;
731
- this . n = Array . from ( this . e . childNodes ) ;
732
+ this . n = Array . from ( this . e . nodeName === 'TEMPLATE' ? ( this . e as HTMLTemplateElement ) . content . childNodes : this . e . childNodes ) ;
732
733
}
733
734
734
735
i ( anchor ) {
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ export default {
6
6
<div>foo</div>
7
7
</template>
8
8
<template id="t2">123</template>
9
+ <template id="t3">1<b>B</b>1</template>
9
10
` ,
10
11
11
12
test ( { assert, target } ) {
@@ -27,5 +28,16 @@ export default {
27
28
assert . equal ( template2 . content . firstChild . textContent , '123' ) ;
28
29
assert . htmlEqual ( template2 . innerHTML , '123' ) ;
29
30
31
+ const template3 = target . querySelector ( '#t3' ) ;
32
+ assert . equal ( template3 . childNodes . length , 0 ) ;
33
+ assert . equal ( template3 . content . childNodes . length , 3 ) ;
34
+ // test: (with hydration from ssr rendered html)
35
+ // out of order render.
36
+ // <template>1{@html '2'}3</template> may render as <template>321</template> for ssr+hydration case.
37
+ // we bypass it by using symmetric siblings. hence <template> is not fully stable for this edge case.
38
+ assert . equal ( template3 . content . childNodes [ 0 ] . textContent , '1' ) ;
39
+ assert . equal ( template3 . content . childNodes [ 1 ] . outerHTML , '<b>B</b>' ) ;
40
+ assert . equal ( template3 . content . childNodes [ 2 ] . textContent , '1' ) ;
41
+
30
42
}
31
43
} ;
Original file line number Diff line number Diff line change 1
1
<template id =" t1" >
2
2
<div >foo</div >
3
3
</template >
4
- <template id =" t2" >123</template >
4
+ <template id =" t2" >123</template >
5
+ <template id ="t3" >1{@html ' <b>B</b>' }1</template >
You can’t perform that action at this time.
0 commit comments