diff --git a/server/commands/documentCollaborativeUpdater.ts b/server/commands/documentCollaborativeUpdater.ts index ae571e9dd1..f2cdc2b2a1 100644 --- a/server/commands/documentCollaborativeUpdater.ts +++ b/server/commands/documentCollaborativeUpdater.ts @@ -72,16 +72,24 @@ export default async function documentCollaborativeUpdater({ ...pudIds, ]); + // Either the client or server version could be null, or they could both be + // set. In that case we want to use the greater (newer) version. + const editorVersion = + document.editorVersion && clientVersion + ? semver.gt(clientVersion, document.editorVersion) + ? clientVersion + : document.editorVersion + : clientVersion + ? clientVersion + : document.editorVersion; + await document.update( { content, state: Buffer.from(state), lastModifiedById, collaboratorIds, - editorVersion: - clientVersion && semver.gt(clientVersion, document.editorVersion) - ? clientVersion - : document.editorVersion, + editorVersion, }, { transaction, diff --git a/server/models/Document.ts b/server/models/Document.ts index d123313068..061661265d 100644 --- a/server/models/Document.ts +++ b/server/models/Document.ts @@ -315,7 +315,7 @@ class Document extends ArchivableModel< msg: `editorVersion must be 255 characters or less`, }) @Column - editorVersion: string; + editorVersion: string | null; /** An icon to use as the document icon. */ @Length({ diff --git a/server/models/Revision.ts b/server/models/Revision.ts index 3fb9a22376..df4db33b55 100644 --- a/server/models/Revision.ts +++ b/server/models/Revision.ts @@ -48,7 +48,7 @@ class Revision extends ParanoidModel< }) @Column @SkipChangeset - editorVersion: string; + editorVersion: string | null; /** The document title at the time of the revision */ @Length({