Skip to content

Commit 9931b71

Browse files
committed
avoid marking slot content as static.
1 parent 4f84aef commit 9931b71

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

src/compiler/optimizer.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ function genStaticKeys (keys: string): Function {
3838
function markStatic (node: ASTNode) {
3939
node.static = isStatic(node)
4040
if (node.type === 1) {
41+
// do not make component slot content static. this avoids
42+
// 1. components not able to mutate slot nodes
43+
// 2. static slot content fails for hot-reloading
44+
if (
45+
!isPlatformReservedTag(node.tag) &&
46+
node.tag !== 'slot' &&
47+
node.attrsMap['inline-template'] == null
48+
) {
49+
return
50+
}
4151
for (let i = 0, l = node.children.length; i < l; i++) {
4252
const child = node.children[i]
4353
markStatic(child)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,7 @@ describe('codegen', () => {
272272
it('generate component', () => {
273273
assertCodegen(
274274
'<my-component name="mycomponent1" :msg="msg" @notify="onNotify"><div>hi</div></my-component>',
275-
`with(this){return _h('my-component',{attrs:{"name":"mycomponent1","msg":msg},on:{"notify":onNotify}},[_m(0)])}`,
276-
[`with(this){return _h('div',["hi"])}`]
275+
`with(this){return _h('my-component',{attrs:{"name":"mycomponent1","msg":msg},on:{"notify":onNotify}},[_h('div',["hi"])])}`
277276
)
278277
})
279278

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,6 @@ describe('optimizer', () => {
9090
expect(ast.children[0].static).toBe(false) // text node
9191
})
9292

93-
it('render tag', () => {
94-
const ast = parse('<render :method="onRender"><p>hello</p></render>', baseOptions)
95-
optimize(ast, baseOptions)
96-
expect(ast.static).toBe(false)
97-
expect(ast.children[0].static).toBe(true)
98-
expect(ast.children[0].children[0].static).toBe(true)
99-
})
100-
10193
it('single slot', () => {
10294
const ast = parse('<slot>hello</slot>', baseOptions)
10395
optimize(ast, baseOptions)
@@ -186,7 +178,7 @@ describe('optimizer', () => {
186178
})
187179

188180
it('custom directive', () => {
189-
const ast = parse('<fom><input type="text" name="field1" :value="msg" v-validate:field1="required"></form>', baseOptions)
181+
const ast = parse('<form><input type="text" name="field1" :value="msg" v-validate:field1="required"></form>', baseOptions)
190182
optimize(ast, baseOptions)
191183
expect(ast.static).toBe(false)
192184
expect(ast.children[0].static).toBe(false)

0 commit comments

Comments
 (0)