@@ -86,7 +86,6 @@ define(function (require, exports, module) {
8686 }
8787
8888 /**
89- * @private
9089 * Inject remote live editor driver and any specified editor providers.
9190 * The remote live editor driver mirrors most of the local live editor driver API
9291 * to provide an interface to the in-browser live editor.
@@ -104,16 +103,16 @@ define(function (require, exports, module) {
104103 }
105104
106105 /**
107- * @private
108106 * Send instructions to remove the live editor from the page in LivePreview.
109107 * @return {$.Promise }
110108 */
111109 function remove ( ) {
112110 if ( _hasEditor === false ) {
113111 var deferred = $ . Deferred ( ) ;
114- return deferred . reject ( ) ;
112+ return deferred . reject ( ) . promise ( ) ;
115113 }
116114
115+ _cache . model = undefined ; // do not move in _reset(), otherwise the _reconnect() scenario misses the cache and fails
117116 _reset ( ) ;
118117 var expr = _namespace + ".remove()" ;
119118 return _call ( expr ) ;
@@ -138,6 +137,10 @@ define(function (require, exports, module) {
138137 hasChanged = false ,
139138 key ;
140139
140+ if ( ! data ) {
141+ remove ( ) ;
142+ }
143+
141144 // sync the local model snapshot with the remote model
142145 _ . forEach ( data , function ( value , key ) {
143146 if ( ! _model [ key ] || ! _ . isEqual ( _model [ key ] , value ) ) {
@@ -155,18 +158,24 @@ define(function (require, exports, module) {
155158 /**
156159 * @private
157160 * Handle failed promises for eval() calls to the inspected page.
158- * Promises can fail if the user manually refreshes the page or navigates
161+ * Promises fail if the user manually refreshes the page or navigates
159162 * because the injected editor files will be lost.
163+ * If this is the case, attempt to reconnect.
160164 *
161- * @param {$.Promise= } result promise result
165+ * Promises also fail because of errors thrown in the remote page.
166+ * If this is the case, remove the editor.
162167 */
163- function _whenRemoteCallFailed ( result ) {
164- if ( result ) {
165- return _reconnect ( ) ;
166- } else {
167- _cache . model = undefined ;
168- return remove ( ) ;
169- }
168+ function _whenRemoteCallFailed ( ) {
169+ // check if the remote editor namespace is still defined on the page
170+ _call ( _namespace )
171+ . then ( function ( response ) {
172+ if ( response . type === "undefined" ) {
173+ _reconnect ( ) ;
174+ } else {
175+ remove ( ) ;
176+ }
177+ } )
178+ . fail ( remove ) ;
170179 }
171180
172181 /**
0 commit comments