diff --git a/services/web/frontend/js/ide/editor/EditorManager.js b/services/web/frontend/js/ide/editor/EditorManager.js
index 378d7b7f77..c1ccf56d80 100644
--- a/services/web/frontend/js/ide/editor/EditorManager.js
+++ b/services/web/frontend/js/ide/editor/EditorManager.js
@@ -302,15 +302,30 @@ export default (EditorManager = (function() {
'Sorry, this file has too many comments or tracked changes. Please try accepting or rejecting some existing changes, or resolving and deleting some comments.'
)
} else {
+ // Do not allow this doc to open another error modal.
+ sharejs_doc.off('error')
+
+ // Preserve the sharejs contents before the teardown.
+ editorContent =
+ typeof editorContent === 'string'
+ ? editorContent
+ : sharejs_doc.doc._doc.snapshot
+
+ // Tear down the ShareJsDoc.
+ if (sharejs_doc.doc) sharejs_doc.doc.clearInflightAndPendingOps()
+
+ // Do not re-join after re-connecting.
+ sharejs_doc.leaveAndCleanUp()
+
this.ide.socket.disconnect()
this.ide.reportError(error, meta)
this.ide.showOutOfSyncModal(
'Out of sync',
"Sorry, this file has gone out of sync and we need to do a full refresh.
Please see this help guide for more information",
- typeof editorContent === 'string'
- ? editorContent
- : sharejs_doc.doc._doc.snapshot
+ editorContent
)
+ // Do not forceReopen the document.
+ return
}
const removeHandler = this.$scope.$on('project:joined', () => {
this.openDoc(doc, { forceReopen: true })
diff --git a/services/web/frontend/js/ide/editor/ShareJsDoc.js b/services/web/frontend/js/ide/editor/ShareJsDoc.js
index 7994fa9ac7..052148d720 100644
--- a/services/web/frontend/js/ide/editor/ShareJsDoc.js
+++ b/services/web/frontend/js/ide/editor/ShareJsDoc.js
@@ -270,6 +270,7 @@ export default (ShareJsDoc = (function() {
}
clearInflightAndPendingOps() {
+ this._clearFatalTimeoutTimer()
this._doc.inflightOp = null
this._doc.inflightCallbacks = []
this._doc.pendingOp = null