diff --git a/packages/lexical-react/src/LexicalCollaborationPlugin.tsx b/packages/lexical-react/src/LexicalCollaborationPlugin.tsx index b3018c1af5f..e69efa7dea1 100644 --- a/packages/lexical-react/src/LexicalCollaborationPlugin.tsx +++ b/packages/lexical-react/src/LexicalCollaborationPlugin.tsx @@ -6,7 +6,7 @@ * */ -import type {Doc} from 'yjs'; +import type {Doc, XmlText} from 'yjs'; import { type CollaborationContextType, @@ -45,6 +45,7 @@ type Props = { excludedProperties?: ExcludedProperties; // `awarenessData` parameter allows arbitrary data to be added to the awareness. awarenessData?: object; + getXmlText?: (doc: Doc) => XmlText; }; export function CollaborationPlugin({ @@ -57,6 +58,7 @@ export function CollaborationPlugin({ initialEditorState, excludedProperties, awarenessData, + getXmlText, }: Props): JSX.Element { const isBindingInitialized = useRef(false); const isProviderInitialized = useRef(false); @@ -117,13 +119,14 @@ export function CollaborationPlugin({ doc || yjsDocMap.get(id), yjsDocMap, excludedProperties, + getXmlText, ); setBinding(newBinding); return () => { newBinding.root.destroy(newBinding); }; - }, [editor, provider, id, yjsDocMap, doc, excludedProperties]); + }, [editor, provider, id, yjsDocMap, doc, excludedProperties, getXmlText]); if (!provider || !binding) { return <>; diff --git a/packages/lexical-yjs/flow/LexicalYjs.js.flow b/packages/lexical-yjs/flow/LexicalYjs.js.flow index 6258a1fce70..019218f3c1c 100644 --- a/packages/lexical-yjs/flow/LexicalYjs.js.flow +++ b/packages/lexical-yjs/flow/LexicalYjs.js.flow @@ -345,6 +345,7 @@ declare export function createBinding( id: string, doc: ?Doc, docMap: Map, + getXmlText: ?(ydoc: Doc) => XmlText ): Binding; declare export function syncCursorPositions( diff --git a/packages/lexical-yjs/src/Bindings.ts b/packages/lexical-yjs/src/Bindings.ts index 5c9bdb8f9e0..3fb4f5cdae7 100644 --- a/packages/lexical-yjs/src/Bindings.ts +++ b/packages/lexical-yjs/src/Bindings.ts @@ -50,12 +50,13 @@ export function createBinding( doc: Doc | null | undefined, docMap: Map, excludedProperties?: ExcludedProperties, + getXmlText = (ydoc: Doc) => ydoc.get('root', XmlText) as XmlText, ): Binding { invariant( doc !== undefined && doc !== null, 'createBinding: doc is null or undefined', ); - const rootXmlText = doc.get('root', XmlText) as XmlText; + const rootXmlText = getXmlText(doc); const root: CollabElementNode = $createCollabElementNode( rootXmlText, null,