Skip to content

Commit 25fd996

Browse files
committed
fix(document load): possible race condition
When two people create a session roughly at the same time they will both be handed the content of the file as no steps have been pushed yet. Use `setContent` rather than loading the document with the content as it is idempotent. Signed-off-by: Max <max@nextcloud.com>
1 parent 1738bdd commit 25fd996

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/EditorFactory.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const loadSyntaxHighlight = async (language) => {
4747
}
4848
}
4949

50-
const createEditor = ({ content, onCreate, onUpdate = () => {}, extensions, enableRichEditing, session, relativePath }) => {
50+
const createEditor = ({ onCreate, onUpdate = () => {}, extensions, enableRichEditing, session, relativePath }) => {
5151
let defaultExtensions
5252
if (enableRichEditing) {
5353
defaultExtensions = [
@@ -68,7 +68,6 @@ const createEditor = ({ content, onCreate, onUpdate = () => {}, extensions, enab
6868
}
6969

7070
return new Editor({
71-
content: content + '<p/>',
7271
onCreate,
7372
onUpdate,
7473
editorProps: {

src/components/Editor.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ export default {
347347
parseContent(documentSource) {
348348
return !this.isRichEditor
349349
? `<pre>${escapeHtml(documentSource)}</pre>`
350-
: markdownit.render(documentSource)
350+
: markdownit.render(documentSource) + '<p/>'
351351
},
352352
353353
initSession() {
@@ -495,7 +495,6 @@ export default {
495495
this.$editor = createEditor({
496496
relativePath: this.relativePath,
497497
session,
498-
content: documentState ? '' : this.parseContent(documentSource),
499498
onCreate: ({ editor }) => {
500499
this.$syncService.startSync()
501500
},
@@ -529,7 +528,9 @@ export default {
529528
enableRichEditing: this.isRichEditor,
530529
})
531530
this.hasEditor = true
532-
531+
if (!documentState && documentSource) {
532+
this.setContent(documentSource)
533+
}
533534
this.listenEditorEvents()
534535
535536
})

0 commit comments

Comments
 (0)