Skip to content

Commit

Permalink
fix: Allows catchup from empty documents
Browse files Browse the repository at this point in the history
Using the jsonTransformer directly introduce a bug for empty documents
with only one paragraph. The transformed document has no content
(not even the paragraph) and makes the Editor to always when think
it is as version=0. This would break the catchup logic.
This patch fixes this unique case, creating a correct empty document with
an empty paragraph
  • Loading branch information
edas committed Feb 6, 2020
1 parent 5d70971 commit 24327ae
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/lib/collab/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ import get from 'lodash/get'
import debounce from 'lodash/debounce'

const jsonTransformer = new JSONTransformer()
// Using the jsonTransformer directly introduce a bug for empty documents
// with only one paragraph. The transformed document has no content
// (not even the paragraph) and makes the Editor to always when think
// it is as version=0. This would break the catchup logic.
// This patch fixes this unique case, creating a correct empty document with
// an empty paragraph
const oldEncode = jsonTransformer.encode.bind(jsonTransformer)
jsonTransformer.encode = function(doc) {
const transformed = oldEncode(doc)
if (transformed.content.length === 0 && doc.content.length != 0) {
return {
content: [{ type: 'paragraph', content: [] }],
type: 'doc'
}
} else {
return transformed
}
}

/**
* The CollabProvider is called directly by the
Expand Down

0 comments on commit 24327ae

Please sign in to comment.