mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-13 06:14:43 +00: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:
parent
d0b6e877dc
commit
8f4ddcbbbb
1 changed files with 16 additions and 1 deletions
|
@ -28,6 +28,7 @@ export default (EditorManager = (function() {
|
|||
}
|
||||
constructor(ide, $scope, localStorage) {
|
||||
this.ide = ide
|
||||
this.editorOpenDocEpoch = 0 // track pending document loads
|
||||
this.$scope = $scope
|
||||
this.localStorage = localStorage
|
||||
this.$scope.editor = {
|
||||
|
@ -178,6 +179,12 @@ export default (EditorManager = (function() {
|
|||
|
||||
this.$scope.editor.opening = true
|
||||
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) {
|
||||
this.ide.showGenericMessageModal(
|
||||
'Error opening document',
|
||||
|
@ -216,11 +223,19 @@ export default (EditorManager = (function() {
|
|||
current_sharejs_doc.leaveAndCleanUp()
|
||||
this._unbindFromDocumentEvents(current_sharejs_doc)
|
||||
}
|
||||
|
||||
const editorOpenDocEpoch = ++this.editorOpenDocEpoch
|
||||
return new_sharejs_doc.join(error => {
|
||||
if (error != null) {
|
||||
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)
|
||||
return callback(null, new_sharejs_doc)
|
||||
})
|
||||
|
|
Loading…
Add table
Reference in a new issue