@@ -17,13 +17,21 @@ import { InlineH1, InlineH2, InlineH3 } from './extensions'
1717export default function TipTapComponent ( { scrollContainerRef } : TipTapComponentProps ) {
1818 const { documentId } = useCurrentDocument ( )
1919 const veltUser = useVeltEventCallback ( 'userUpdate' )
20+ const [ hasInitialized , setHasInitialized ] = React . useState ( false )
2021
21- // Initialize CRDT extension
22- const { VeltCrdt } = useVeltTiptapCrdtExtension ( {
23- editorId : documentId || 'default-editor' ,
22+ // Initialize CRDT extension without initialContent to avoid encryption errors
23+ // We'll set initial content manually after the editor is ready
24+ const { VeltCrdt, isLoading } = useVeltTiptapCrdtExtension ( {
25+ editorId : documentId ,
26+ onSynced : ( doc ) => {
27+ console . log ( 'Document synced successfully' , doc )
28+ } ,
29+ onConnectionError : ( error ) => {
30+ console . error ( 'CRDT connection error:' , error )
31+ }
2432 } )
2533
26- // Initialize the editor
34+ // Initialize the editor with empty content
2735 const editor = useEditor ( {
2836 extensions : [
2937 StarterKit . configure ( {
@@ -40,9 +48,30 @@ export default function TipTapComponent({ scrollContainerRef }: TipTapComponentP
4048 TiptapVeltComments ,
4149 ...( VeltCrdt ? [ VeltCrdt ] : [ ] ) ,
4250 ] ,
43- content : initialContent ,
51+ content : '' , // Start with empty content
52+ immediatelyRender : false ,
4453 } , [ VeltCrdt ] )
4554
55+ // Set initial content if document is empty after editor initializes
56+ useEffect ( ( ) => {
57+ if ( editor && ! isLoading && ! hasInitialized ) {
58+ // Small delay to ensure CRDT has fully loaded
59+ const timer = setTimeout ( ( ) => {
60+ const currentText = editor . getText ( )
61+ console . log ( 'Current editor text:' , currentText )
62+
63+ // If document is completely empty, set initial content
64+ if ( ! currentText || currentText . trim ( ) . length === 0 ) {
65+ console . log ( 'Setting initial content...' )
66+ editor . commands . setContent ( initialContent )
67+ }
68+ setHasInitialized ( true )
69+ } , 1000 ) // Wait 1 second for CRDT to fully sync
70+
71+ return ( ) => clearTimeout ( timer )
72+ }
73+ } , [ editor , isLoading , hasInitialized ] )
74+
4675 // Comment annotations
4776 const commentAnnotations = useCommentAnnotations ( )
4877
@@ -65,10 +94,16 @@ export default function TipTapComponent({ scrollContainerRef }: TipTapComponentP
6594 < div className = "w-full max-w-[850px]" >
6695 < div className = "bg-[rgb(17,17,17)] border border-[rgb(20,20,20)] border-solid rounded-[16px] p-[42px_56px_64px_56px] min-h-[880px]" >
6796 < div className = "w-full max-w-[738px]" >
68- < EditorContent
69- editor = { editor }
70- className = "tiptap-editor-content prose prose-invert max-w-none"
71- />
97+ { isLoading ? (
98+ < div className = "flex items-center justify-center h-32 text-gray-400" >
99+ Loading editor...
100+ </ div >
101+ ) : (
102+ < EditorContent
103+ editor = { editor }
104+ className = "tiptap-editor-content prose prose-invert max-w-none"
105+ />
106+ ) }
72107 </ div >
73108
74109 { /* Bubble Menu for Comments */ }
0 commit comments