Skip to content

Commit

Permalink
[#53027] Do null checks on ycomments
Browse files Browse the repository at this point in the history
  • Loading branch information
MaciejWas committed Feb 16, 2024
1 parent 05fa2b1 commit 7c0c2f4
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/components/CodeMirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const CodeMirror = ({ text, setText, id, name, className, mode, syncText, setSyn
extensions: ExtensionBuilder.basicSetup()
.useHighlighter(highlights)
.useSpellcheck(spellcheckOpts)
.useCollaboration({enabled: collaboration.enabled, ytext, undoManager, provider, editorRef})
.useCollaboration({enabled: collaboration.enabled || false, ytext, undoManager, provider, editorRef})
.useComments({enabled: collaboration.commentsEnabled, ycomments})
.addUpdateListener(update => update.docChanged && setText(view.state.doc.toString()))
.create()
Expand All @@ -149,7 +149,9 @@ const CodeMirror = ({ text, setText, id, name, className, mode, syncText, setSyn
editorRef.current = view;
setInitialized(true);

ycomments.registerCodeMirror(view);
if (ycomments) {
ycomments.registerCodeMirror(view);
}

return () => {
if (collaboration.enabled) {
Expand All @@ -174,8 +176,10 @@ const CodeMirror = ({ text, setText, id, name, className, mode, syncText, setSyn
console.log('You are the first user in this document. Initiating...');
setEditorText(editorRef.current, text);
}

ycomments.updateMainCodeMirror();

if (ycomments) {
ycomments.updateMainCodeMirror();
}
}, [ready, initialized]);

useEffect(() => {
Expand Down

0 comments on commit 7c0c2f4

Please sign in to comment.