Skip to content
This repository was archived by the owner on May 11, 2026. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions app/components/editor/Tiptap.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use client';
import { useEffect } from 'react';
import { useEffect, useRef } from 'react';
import { EditorContent, useEditor } from '@tiptap/react';
import StarterKit from '@tiptap/starter-kit';
import Underline from '@tiptap/extension-underline';
Expand All @@ -9,11 +9,16 @@ const Tiptap: React.FC<{
onChange: (newContent: string) => void;
content: string;
}> = ({ onChange, content }) => {
const lastAppliedContentRef = useRef(content);

const handleChange = (newContent: string) => {
lastAppliedContentRef.current = newContent;
onChange(newContent);
};

const editor = useEditor({
extensions: [StarterKit, Underline],
content,
editorProps: {
attributes: {
class:
Expand All @@ -24,12 +29,13 @@ const Tiptap: React.FC<{
handleChange(editor.getHTML());
},
});

useEffect(() => {
if (!editor) return;
const value = content;
if (value) {
editor.commands.setContent(value);
}
if (content === lastAppliedContentRef.current) return;

editor.commands.setContent(content, false);
lastAppliedContentRef.current = content;
}, [editor, content]);

return (
Expand Down