Skip to content

Commit 5875c7c

Browse files
committed
fix: revert shared static tree cache to avoid memory leak
revert f0a66c5 fix #7184
1 parent 0da8bce commit 5875c7c

File tree

3 files changed

+13
-21
lines changed

3 files changed

+13
-21
lines changed

src/compiler/codegen/index.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,13 @@ export function genElement (el: ASTElement, state: CodegenState): string {
8686
}
8787

8888
// hoist static sub-trees out
89-
function genStatic (el: ASTElement, state: CodegenState, once: ?boolean): string {
89+
function genStatic (el: ASTElement, state: CodegenState): string {
9090
el.staticProcessed = true
9191
state.staticRenderFns.push(`with(this){return ${genElement(el, state)}}`)
9292
return `_m(${
9393
state.staticRenderFns.length - 1
94-
},${
95-
el.staticInFor ? 'true' : 'false'
96-
},${
97-
once ? 'true' : 'false'
94+
}${
95+
el.staticInFor ? ',true' : ''
9896
})`
9997
}
10098

@@ -121,7 +119,7 @@ function genOnce (el: ASTElement, state: CodegenState): string {
121119
}
122120
return `_o(${genElement(el, state)},${state.onceId++},${key})`
123121
} else {
124-
return genStatic(el, state, true)
122+
return genStatic(el, state)
125123
}
126124
}
127125

src/core/instance/render-helpers/render-static.js

+7-13
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,9 @@ import { cloneVNode, cloneVNodes } from 'core/vdom/vnode'
77
*/
88
export function renderStatic (
99
index: number,
10-
isInFor: boolean,
11-
isOnce: boolean
10+
isInFor: boolean
1211
): VNode | Array<VNode> {
13-
// render fns generated by compiler < 2.5.4 does not provide v-once
14-
// information to runtime so be conservative
15-
const isOldVersion = arguments.length < 3
16-
// if a static tree is generated by v-once, it is cached on the instance;
17-
// otherwise it is purely static and can be cached on the shared options
18-
// across all instances.
19-
const renderFns = this.$options.staticRenderFns
20-
const cached = isOldVersion || isOnce
21-
? (this._staticTrees || (this._staticTrees = []))
22-
: (renderFns.cached || (renderFns.cached = []))
12+
const cached = this._staticTrees || (this._staticTrees = [])
2313
let tree = cached[index]
2414
// if has already-rendered static tree and not inside v-for,
2515
// we can reuse the same tree by doing a shallow clone.
@@ -29,7 +19,11 @@ export function renderStatic (
2919
: cloneVNode(tree)
3020
}
3121
// otherwise, render a fresh tree.
32-
tree = cached[index] = renderFns[index].call(this._renderProxy, null, this)
22+
tree = cached[index] = this.$options.staticRenderFns[index].call(
23+
this._renderProxy,
24+
null,
25+
this // for render fns generated for functional component templates
26+
)
3327
markStatic(tree, `__static__${index}`, false)
3428
return tree
3529
}

test/unit/modules/compiler/codegen.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ describe('codegen', () => {
478478
// have "inline-template'"
479479
assertCodegen(
480480
'<my-component inline-template><p><span>hello world</span></p></my-component>',
481-
`with(this){return _c('my-component',{inlineTemplate:{render:function(){with(this){return _m(0,false,false)}},staticRenderFns:[function(){with(this){return _c('p',[_c('span',[_v("hello world")])])}}]}})}`
481+
`with(this){return _c('my-component',{inlineTemplate:{render:function(){with(this){return _m(0)}},staticRenderFns:[function(){with(this){return _c('p',[_c('span',[_v("hello world")])])}}]}})}`
482482
)
483483
// "have inline-template attrs, but not having exactly one child element
484484
assertCodegen(
@@ -498,7 +498,7 @@ describe('codegen', () => {
498498
it('generate static trees inside v-for', () => {
499499
assertCodegen(
500500
`<div><div v-for="i in 10"><p><span></span></p></div></div>`,
501-
`with(this){return _c('div',_l((10),function(i){return _c('div',[_m(0,true,false)])}))}`,
501+
`with(this){return _c('div',_l((10),function(i){return _c('div',[_m(0,true)])}))}`,
502502
[`with(this){return _c('p',[_c('span')])}`]
503503
)
504504
})

0 commit comments

Comments
 (0)