From cd8212f32768bded8720713daacd07f0c84191b1 Mon Sep 17 00:00:00 2001 From: Palanikannan M Date: Tue, 24 Dec 2024 17:37:36 +0530 Subject: [PATCH] fix: add editor rerendering optimization --- live/package.json | 4 ---- packages/editor/package.json | 20 ------------------ packages/editor/src/core/hooks/use-editor.ts | 22 ++++---------------- 3 files changed, 4 insertions(+), 42 deletions(-) diff --git a/live/package.json b/live/package.json index 52521749147..480da4726c2 100644 --- a/live/package.json +++ b/live/package.json @@ -20,10 +20,6 @@ "@hocuspocus/extension-logger": "^2.15.0", "@hocuspocus/extension-redis": "^2.15.0", "@hocuspocus/server": "^2.15.0", - "@hocuspocus/extension-database": "^2.11.3", - "@hocuspocus/extension-logger": "^2.11.3", - "@hocuspocus/extension-redis": "^2.13.5", - "@hocuspocus/server": "^2.11.3", "@plane/constants": "*", "@plane/editor": "*", "@plane/types": "*", diff --git a/packages/editor/package.json b/packages/editor/package.json index 620413eac9f..3cc4269fb49 100644 --- a/packages/editor/package.json +++ b/packages/editor/package.json @@ -55,27 +55,7 @@ "@tiptap/starter-kit": "^2.10.3", "@tiptap/suggestion": "^2.10.3", "clsx": "^2.0.0", - "@hocuspocus/provider": "^2.13.5", "@plane/types": "*", - "@plane/ui": "*", - "@plane/utils": "*", - "@tiptap/core": "^2.1.13", - "@tiptap/extension-blockquote": "^2.1.13", - "@tiptap/extension-character-count": "^2.6.5", - "@tiptap/extension-collaboration": "^2.3.2", - "@tiptap/extension-image": "^2.1.13", - "@tiptap/extension-list-item": "^2.1.13", - "@tiptap/extension-mention": "^2.1.13", - "@tiptap/extension-placeholder": "^2.3.0", - "@tiptap/extension-task-item": "^2.1.13", - "@tiptap/extension-task-list": "^2.1.13", - "@tiptap/extension-text-align": "^2.8.0", - "@tiptap/extension-text-style": "^2.7.1", - "@tiptap/extension-underline": "^2.1.13", - "@tiptap/pm": "^2.1.13", - "@tiptap/react": "^2.1.13", - "@tiptap/starter-kit": "^2.1.13", - "@tiptap/suggestion": "^2.0.13", "class-variance-authority": "^0.7.0", "highlight.js": "^11.8.0", "jsx-dom-cjs": "^8.0.3", diff --git a/packages/editor/src/core/hooks/use-editor.ts b/packages/editor/src/core/hooks/use-editor.ts index 9a797adf466..b53ee8112fa 100644 --- a/packages/editor/src/core/hooks/use-editor.ts +++ b/packages/editor/src/core/hooks/use-editor.ts @@ -112,6 +112,8 @@ export const useEditor = (props: CustomEditorProps) => { const editor = useTiptapEditor( { editable, + immediatelyRender: true, + shouldRerenderOnTransaction: false, autofocus, editorProps: { ...CoreEditorProps({ @@ -133,8 +135,7 @@ export const useEditor = (props: CustomEditorProps) => { ], content: typeof initialValue === "string" && initialValue.trim() !== "" ? initialValue : "

", onCreate: () => handleEditorReady?.(true), - onTransaction: ({ editor }) => { - setSavedSelection(editor.state.selection); + onTransaction: () => { onTransaction?.(); }, onUpdate: ({ editor }) => onChange?.(editor.getJSON(), editor.getHTML()), @@ -143,18 +144,6 @@ export const useEditor = (props: CustomEditorProps) => { [editable] ); - const editorState = useEditorState({ - editor, - // This function will be called every time the editor state changes - selector: ({ editor: editorInstance }: { editor: Editor }) => ({ - // It will only re-render if the bold or italic state changes - isBold: editorInstance.isActive("bold"), - isItalic: editorInstance.isActive("italic"), - }), - }); - - console.log("editorState", editorState); - const [currentEditorState, setCurrentEditorState] = useState(editorState); // Effect for syncing SWR data useEffect(() => { // value is null when intentionally passed where syncing is not yet @@ -173,9 +162,6 @@ export const useEditor = (props: CustomEditorProps) => { } } }, [editor, value, id]); - useEffect(() => { - setCurrentEditorState(editorState); - }, [editorState]); useImperativeHandle( forwardedRef, @@ -330,7 +316,7 @@ export const useEditor = (props: CustomEditorProps) => { emitRealTimeUpdate: (message: TDocumentEventsServer) => provider?.sendStateless(message), listenToRealTimeUpdate: () => provider && { on: provider.on.bind(provider), off: provider.off.bind(provider) }, }), - [editor, currentEditorState] + [editor] ); if (!editor) {