Skip to content

Commit 45effc1

Browse files
committed
Initial content
1 parent 3f723d3 commit 45effc1

File tree

5 files changed

+235
-17
lines changed

5 files changed

+235
-17
lines changed

apps/react/text-editors/libraries/tiptap/tiptap-demo/app/document/DocumentContext.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,9 @@ export function useCurrentDocument(): CurrentDocument {
2020
setDocumentId(docId);
2121
localStorage.setItem('tiptap-document-id', docId);
2222
} else {
23-
const stored = localStorage.getItem('tiptap-document-id');
24-
if (stored) {
25-
docId = stored;
26-
} else {
27-
docId = `doc-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
28-
localStorage.setItem('tiptap-document-id', docId);
29-
}
23+
// Always create a new document with timestamp to ensure fresh start
24+
docId = `doc-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
25+
localStorage.setItem('tiptap-document-id', docId);
3026

3127
const newUrl = `${window.location.pathname}?documentId=${docId}`;
3228
window.history.pushState({}, '', newUrl);

apps/react/text-editors/libraries/tiptap/tiptap-demo/components/document/TipTapComponent/TipTapComponent.tsx

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,21 @@ import { InlineH1, InlineH2, InlineH3 } from './extensions'
1717
export 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

Comments
 (0)