Skip to content

Commit

Permalink
fix: an untested version that should be more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
nperez0111 committed Jun 14, 2024
1 parent 42dee59 commit 7138eac
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions packages/extension-collaboration/src/collaboration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Extension } from '@tiptap/core'
import { Plugin, PluginKey } from '@tiptap/pm/state'
import type { ReplaceStep } from '@tiptap/pm/transform'
import { EditorView } from '@tiptap/pm/view'
import {
redo,
Expand Down Expand Up @@ -186,27 +185,22 @@ export const Collaboration = Extension.create<CollaborationOptions>({
this.editor.options.enableContentCheck
&& new Plugin({
key: new PluginKey('filterInvalidContent'),
filterTransaction: transaction => {
filterTransaction: tr => {
// Is this transaction from Yjs Sync Plugin?
if (isChangeOrigin(transaction)) {
if (isChangeOrigin(tr)) {

// When collaboration is disabled, prevent any sync transactions from being applied
if (isCollaborationDisabled) {
return true
}

// Is this the expected, single replace step?
if (transaction.steps.length === 1 && (transaction.steps[0] as any).jsonID === 'replace') {
const step = transaction.steps[0] as ReplaceStep
// Did the doc actually change as a result of this transaction?
if (tr.docChanged) {

// Attempt to parse the content of the step
try {
const content = step.slice.content.toJSON()
const content = tr.doc.toJSON()

if (Array.isArray(content)) {
content.forEach(node => this.editor.schema.nodeFromJSON(node))
return true
}
this.editor.schema.nodeFromJSON(content)
} catch (error) {
this.editor.emit('contentError', {
Expand Down

0 comments on commit 7138eac

Please sign in to comment.