@@ -4,7 +4,7 @@ export const svgNS = 'http://www.w3.org/2000/svg'
4
4
5
5
const doc = ( typeof document !== 'undefined' ? document : null ) as Document
6
6
7
- const staticTemplateCache = new Map < string , DocumentFragment > ( )
7
+ const templateContainer = doc && doc . createElement ( 'template' )
8
8
9
9
export const nodeOps : Omit < RendererOptions < Node , Element > , 'patchProp' > = {
10
10
insert : ( child , parent , anchor ) => {
@@ -73,14 +73,19 @@ export const nodeOps: Omit<RendererOptions<Node, Element>, 'patchProp'> = {
73
73
// Reason: innerHTML.
74
74
// Static content here can only come from compiled templates.
75
75
// As long as the user only uses trusted templates, this is safe.
76
- insertStaticContent ( content , parent , anchor , isSVG ) {
76
+ insertStaticContent ( content , parent , anchor , isSVG , start , end ) {
77
77
// <parent> before | first ... last | anchor </parent>
78
78
const before = anchor ? anchor . previousSibling : parent . lastChild
79
- let template = staticTemplateCache . get ( content )
80
- if ( ! template ) {
81
- const t = doc . createElement ( 'template' )
82
- t . innerHTML = isSVG ? `<svg>${ content } </svg>` : content
83
- template = t . content
79
+ if ( start && end ) {
80
+ // cached
81
+ while ( true ) {
82
+ parent . insertBefore ( start ! . cloneNode ( true ) , anchor )
83
+ if ( start === end || ! ( start = start ! . nextSibling ) ) break
84
+ }
85
+ } else {
86
+ // fresh insert
87
+ templateContainer . innerHTML = isSVG ? `<svg>${ content } </svg>` : content
88
+ const template = templateContainer . content
84
89
if ( isSVG ) {
85
90
// remove outer svg wrapper
86
91
const wrapper = template . firstChild !
@@ -89,9 +94,8 @@ export const nodeOps: Omit<RendererOptions<Node, Element>, 'patchProp'> = {
89
94
}
90
95
template . removeChild ( wrapper )
91
96
}
92
- staticTemplateCache . set ( content , template )
97
+ parent . insertBefore ( template , anchor )
93
98
}
94
- parent . insertBefore ( template . cloneNode ( true ) , anchor )
95
99
return [
96
100
// first
97
101
before ? before . nextSibling ! : parent . firstChild ! ,
0 commit comments