@@ -12,11 +12,15 @@ module.exports = {
12
12
this . end = document . createComment ( 'v-if-end' )
13
13
_ . replace ( el , this . end )
14
14
_ . before ( this . start , this . end )
15
+
16
+ // Note: content transclusion is not available for
17
+ // <template> blocks
15
18
if ( el . tagName === 'TEMPLATE' ) {
16
19
this . template = templateParser . parse ( el , true )
17
20
} else {
18
21
this . template = document . createDocumentFragment ( )
19
- this . template . appendChild ( el )
22
+ this . template . appendChild ( templateParser . clone ( el ) )
23
+ this . checkContent ( )
20
24
}
21
25
// compile the nested partial
22
26
this . linker = compile (
@@ -33,26 +37,50 @@ module.exports = {
33
37
}
34
38
} ,
35
39
40
+ // check if there are any content nodes from parent.
41
+ // these nodes are compiled by the parent and should
42
+ // not be cloned during a re-compilation - otherwise the
43
+ // parent directives bound to them will no longer work.
44
+ // (see #736)
45
+ checkContent : function ( ) {
46
+ var el = this . el
47
+ for ( var i = 0 ; i < el . childNodes . length ; i ++ ) {
48
+ var node = el . childNodes [ i ]
49
+ // _isContent is a flag set in instance/compile
50
+ // after the raw content has been compiled by parent
51
+ if ( node . _isContent ) {
52
+ ; ( this . contentNodes = this . contentNodes || [ ] ) . push ( node )
53
+ ; ( this . contentPositions = this . contentPositions || [ ] ) . push ( i )
54
+ }
55
+ }
56
+ } ,
57
+
36
58
update : function ( value ) {
37
59
if ( this . invalid ) return
38
60
if ( value ) {
39
- this . insert ( )
61
+ // avoid duplicate compiles, since update() can be
62
+ // called with different truthy values
63
+ if ( ! this . unlink ) {
64
+ var frag = templateParser . clone ( this . template )
65
+ // persist content nodes from parent.
66
+ if ( this . contentNodes ) {
67
+ var el = frag . childNodes [ 0 ]
68
+ for ( var i = 0 , l = this . contentNodes . length ; i < l ; i ++ ) {
69
+ var node = this . contentNodes [ i ]
70
+ var j = this . contentPositions [ i ]
71
+ el . replaceChild ( node , el . childNodes [ j ] )
72
+ }
73
+ }
74
+ this . compile ( frag )
75
+ }
40
76
} else {
41
77
this . teardown ( )
42
78
}
43
79
} ,
44
80
45
- insert : function ( ) {
46
- // avoid duplicate inserts, since update() can be
47
- // called with different truthy values
48
- if ( ! this . unlink ) {
49
- this . compile ( this . template )
50
- }
51
- } ,
52
-
53
- compile : function ( template ) {
81
+ // NOTE: this function is shared in v-partial
82
+ compile : function ( frag ) {
54
83
var vm = this . vm
55
- var frag = templateParser . clone ( template )
56
84
var originalChildLength = vm . _children . length
57
85
this . unlink = this . linker
58
86
? this . linker ( vm , frag )
@@ -66,6 +94,7 @@ module.exports = {
66
94
}
67
95
} ,
68
96
97
+ // NOTE: this function is shared in v-partial
69
98
teardown : function ( ) {
70
99
if ( ! this . unlink ) return
71
100
transition . blockRemove ( this . start , this . end , this . vm )
0 commit comments