@@ -36,6 +36,8 @@ module.exports = {
3636 // extract inline template as a DocumentFragment
3737 this . template = _ . extractContent ( this . el , true )
3838 }
39+ // pending callback for async component resolution
40+ this . _pendingCb = null
3941 // if static, build right now.
4042 if ( ! this . _isDynamicLiteral ) {
4143 this . resolveCtor ( this . expression , _ . bind ( function ( ) {
@@ -63,13 +65,27 @@ module.exports = {
6365
6466 resolveCtor : function ( id , cb ) {
6567 var self = this
66- // TODO handle update/teardown before the component
67- // is actually resolved
68- this . vm . _resolveComponent ( id , function ( ctor ) {
69- self . ctorId = id
70- self . Ctor = ctor
71- cb ( )
72- } )
68+ var pendingCb = this . _pendingCb = function ( ctor ) {
69+ if ( ! pendingCb . invalidated ) {
70+ self . ctorId = id
71+ self . Ctor = ctor
72+ cb ( )
73+ }
74+ }
75+ this . vm . _resolveComponent ( id , pendingCb )
76+ } ,
77+
78+ /**
79+ * When the component changes or unbinds before an async
80+ * constructor is resolved, we need to invalidate its
81+ * pending callback.
82+ */
83+
84+ invalidatePending : function ( ) {
85+ if ( this . _pendingCb ) {
86+ this . _pendingCb . invalidated = true
87+ this . _pendingCb = null
88+ }
7389 } ,
7490
7591 /**
@@ -144,9 +160,9 @@ module.exports = {
144160 */
145161
146162 update : function ( value ) {
163+ this . invalidatePending ( )
147164 if ( ! value ) {
148165 // just remove current
149- this . unbuild ( )
150166 this . remove ( this . childVM )
151167 this . unsetCurrent ( )
152168 } else {
@@ -224,6 +240,7 @@ module.exports = {
224240 */
225241
226242 unbind : function ( ) {
243+ this . invalidatePending ( )
227244 this . unbuild ( )
228245 // destroy all keep-alive cached instances
229246 if ( this . cache ) {
0 commit comments