mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 22:23:42 +01:00
Merge pull request #3170 from overleaf/fix-editor-race
discard previous doc load when new doc opened GitOrigin-RevId: 0bbbb94b6ca5ebd4b5a0b4e3472f705d5337cdf5
This commit is contained in:
@@ -28,6 +28,7 @@ export default (EditorManager = (function() {
|
|||||||
}
|
}
|
||||||
constructor(ide, $scope, localStorage) {
|
constructor(ide, $scope, localStorage) {
|
||||||
this.ide = ide
|
this.ide = ide
|
||||||
|
this.editorOpenDocEpoch = 0 // track pending document loads
|
||||||
this.$scope = $scope
|
this.$scope = $scope
|
||||||
this.localStorage = localStorage
|
this.localStorage = localStorage
|
||||||
this.$scope.editor = {
|
this.$scope.editor = {
|
||||||
@@ -178,6 +179,12 @@ export default (EditorManager = (function() {
|
|||||||
|
|
||||||
this.$scope.editor.opening = true
|
this.$scope.editor.opening = true
|
||||||
return this._openNewDocument(doc, (error, sharejs_doc) => {
|
return this._openNewDocument(doc, (error, sharejs_doc) => {
|
||||||
|
if (error && error.message === 'another document was loaded') {
|
||||||
|
sl_console.log(
|
||||||
|
`[openDoc] another document was loaded while ${doc.id} was loading`
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
this.ide.showGenericMessageModal(
|
this.ide.showGenericMessageModal(
|
||||||
'Error opening document',
|
'Error opening document',
|
||||||
@@ -216,11 +223,19 @@ export default (EditorManager = (function() {
|
|||||||
current_sharejs_doc.leaveAndCleanUp()
|
current_sharejs_doc.leaveAndCleanUp()
|
||||||
this._unbindFromDocumentEvents(current_sharejs_doc)
|
this._unbindFromDocumentEvents(current_sharejs_doc)
|
||||||
}
|
}
|
||||||
|
const editorOpenDocEpoch = ++this.editorOpenDocEpoch
|
||||||
return new_sharejs_doc.join(error => {
|
return new_sharejs_doc.join(error => {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
return callback(error)
|
return callback(error)
|
||||||
}
|
}
|
||||||
|
if (this.editorOpenDocEpoch !== editorOpenDocEpoch) {
|
||||||
|
sl_console.log(
|
||||||
|
`[openNewDocument] editorOpenDocEpoch mismatch ${
|
||||||
|
this.editorOpenDocEpoch
|
||||||
|
} vs ${editorOpenDocEpoch}`
|
||||||
|
)
|
||||||
|
return callback(new Error('another document was loaded'))
|
||||||
|
}
|
||||||
this._bindToDocumentEvents(doc, new_sharejs_doc)
|
this._bindToDocumentEvents(doc, new_sharejs_doc)
|
||||||
return callback(null, new_sharejs_doc)
|
return callback(null, new_sharejs_doc)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user