Skip to content

Commit 6cd3a16

Browse files
committed
root node linking should happen after content compilation (fix vuejs#1120)
1 parent 659fc54 commit 6cd3a16

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

src/compiler/compile.js

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,13 @@ exports.compileAndLinkProps = function (vm, el, props) {
148148
*
149149
* If this is a fragment instance, we only need to compile 1.
150150
*
151-
* This function does compile and link at the same time,
152-
* since root linkers can not be reused. It returns the
153-
* unlink function for potential context directives on the
154-
* container.
155-
*
156151
* @param {Vue} vm
157152
* @param {Element} el
158153
* @param {Object} options
159154
* @return {Function}
160155
*/
161156

162-
exports.compileAndLinkRoot = function (vm, el, options) {
157+
exports.compileRoot = function (el, options) {
163158
var containerAttrs = options._containerAttrs
164159
var replacerAttrs = options._replacerAttrs
165160
var contextLinkFn, replacerLinkFn
@@ -184,23 +179,25 @@ exports.compileAndLinkRoot = function (vm, el, options) {
184179
}
185180
}
186181

187-
// link context scope dirs
188-
var context = vm._context
189-
var contextDirs
190-
if (context && contextLinkFn) {
191-
contextDirs = linkAndCapture(function () {
192-
contextLinkFn(context, el)
193-
}, context)
194-
}
182+
return function rootLinkFn (vm, el) {
183+
// link context scope dirs
184+
var context = vm._context
185+
var contextDirs
186+
if (context && contextLinkFn) {
187+
contextDirs = linkAndCapture(function () {
188+
contextLinkFn(context, el)
189+
}, context)
190+
}
195191

196-
// link self
197-
var selfDirs = linkAndCapture(function () {
198-
if (replacerLinkFn) replacerLinkFn(vm, el)
199-
}, vm)
192+
// link self
193+
var selfDirs = linkAndCapture(function () {
194+
if (replacerLinkFn) replacerLinkFn(vm, el)
195+
}, vm)
200196

201-
// return the unlink function that tearsdown context
202-
// container directives.
203-
return makeUnlinkFn(vm, selfDirs, context, contextDirs)
197+
// return the unlink function that tearsdown context
198+
// container directives.
199+
return makeUnlinkFn(vm, selfDirs, context, contextDirs)
200+
}
204201
}
205202

206203
/**

src/instance/compile.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,28 @@ exports._compile = function (el) {
3434

3535
// root is always compiled per-instance, because
3636
// container attrs and props can be different every time.
37-
var rootUnlinkFn =
38-
compiler.compileAndLinkRoot(this, el, options)
37+
var rootLinker = compiler.compileRoot(el, options)
3938

4039
// compile and link the rest
41-
var linker
40+
var contentLinkFn
4241
var ctor = this.constructor
4342
// component compilation can be cached
4443
// as long as it's not using inline-template
4544
if (options._linkerCachable) {
46-
linker = ctor.linker
47-
if (!linker) {
48-
linker = ctor.linker = compiler.compile(el, options)
45+
contentLinkFn = ctor.linker
46+
if (!contentLinkFn) {
47+
contentLinkFn = ctor.linker = compiler.compile(el, options)
4948
}
5049
}
51-
var contentUnlinkFn = linker
52-
? linker(this, el)
50+
51+
// link phase
52+
var rootUnlinkFn = rootLinker(this, el)
53+
var contentUnlinkFn = contentLinkFn
54+
? contentLinkFn(this, el)
5355
: compiler.compile(el, options)(this, el, host)
5456

57+
// register composite unlink function
58+
// to be called during instance destruction
5559
this._unlinkFn = function () {
5660
rootUnlinkFn()
5761
// passing destroying: true to avoid searching and

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy