diff --git a/app/models/Document.js b/app/models/Document.js index 33752d59fe..fdc2870c81 100644 --- a/app/models/Document.js +++ b/app/models/Document.js @@ -10,12 +10,12 @@ import BaseModel from "models/BaseModel"; import User from "models/User"; import View from "./View"; -type SaveOptions = { +type SaveOptions = {| publish?: boolean, done?: boolean, autosave?: boolean, lastRevision?: number, -}; +|}; export default class Document extends BaseModel { @observable isSaving: boolean = false; diff --git a/app/scenes/Document/components/Document.js b/app/scenes/Document/components/Document.js index 5af242cfdd..db275b4b47 100644 --- a/app/scenes/Document/components/Document.js +++ b/app/scenes/Document/components/Document.js @@ -1,6 +1,6 @@ // @flow import { debounce } from "lodash"; -import { observable } from "mobx"; +import { action, observable } from "mobx"; import { observer, inject } from "mobx-react"; import { InputIcon } from "outline-icons"; import { AllSelection } from "prosemirror-state"; @@ -120,7 +120,12 @@ class DocumentScene extends React.Component { this.title = template.title; this.isDirty = true; - const { view, parser } = this.editor.current; + const editorRef = this.editor.current; + if (!editorRef) { + return; + } + + const { view, parser } = editorRef; view.dispatch( view.state.tr .setSelection(new AllSelection(view.state.doc)) @@ -231,13 +236,12 @@ class DocumentScene extends React.Component { document.title = title; document.text = text; + document.tasks = getTasks(document.text); let isNew = !document.id; this.isSaving = true; this.isPublishing = !!options.publish; - document.tasks = getTasks(document.text); - try { let savedDocument = document; if (auth.team?.features.multiplayerEditor) { @@ -299,13 +303,21 @@ class DocumentScene extends React.Component { }; onChange = (getEditorText) => { - const { auth } = this.props; - if (auth.team?.features.multiplayerEditor) { - return; - } + const { document, auth } = this.props; this.getEditorText = getEditorText; + // If the multiplayer editor is enabled then we still want to keep the local + // text value in sync as it is used as a cache. + if (auth.team?.features.multiplayerEditor) { + action(() => { + document.text = this.getEditorText(); + document.tasks = getTasks(document.text); + })(); + + return; + } + // document change while read only is presumed to be a checkbox edit, // in that case we don't delay in saving for a better user experience. if (this.props.readOnly) { diff --git a/server/models/Team.test.js b/server/models/Team.test.js index 8bc465eb98..9d5d5d4757 100644 --- a/server/models/Team.test.js +++ b/server/models/Team.test.js @@ -56,7 +56,7 @@ describe("provisionSubdomain", () => { }); describe("save", () => { - it("should ot allow known features", async () => { + it("should allow known features", async () => { const team = await buildTeam(); team.features = { multiplayerEditor: true };