diff --git a/packages/frontend/core/src/components/page-detail-editor.tsx b/packages/frontend/core/src/components/page-detail-editor.tsx index 32943ae8e2..21b67a2854 100644 --- a/packages/frontend/core/src/components/page-detail-editor.tsx +++ b/packages/frontend/core/src/components/page-detail-editor.tsx @@ -9,15 +9,7 @@ import { fontStyleOptions } from '@toeverything/infra/atom'; import clsx from 'clsx'; import { useAtomValue } from 'jotai'; import type { CSSProperties } from 'react'; -import { - memo, - Suspense, - useCallback, - useEffect, - useMemo, - useRef, - useState, -} from 'react'; +import { memo, Suspense, useCallback, useMemo } from 'react'; import { useLocation } from 'react-router-dom'; import { type PageMode, pageSettingFamily } from '../atoms'; @@ -96,14 +88,14 @@ const PageDetailEditorMain = memo(function PageDetailEditorMain({ [isPublic, switchToEdgelessMode, pageId, switchToPageMode] ); - const [editor, setEditor] = useState(); + const [, setActiveBlocksuiteEditor] = useActiveBlocksuiteEditor(); const blockId = useRouterHash(); const onLoadEditor = useCallback( (editor: AffineEditorContainer) => { // debug current detail editor globalThis.currentEditor = editor; - setEditor(editor); + setActiveBlocksuiteEditor(editor); const disposableGroup = new DisposableGroup(); disposableGroup.add( page.slots.blockUpdated.once(() => { @@ -121,18 +113,9 @@ const PageDetailEditorMain = memo(function PageDetailEditorMain({ disposableGroup.dispose(); }; }, - [onLoad, page] + [onLoad, page, setActiveBlocksuiteEditor] ); - const [, setActiveBlocksuiteEditor] = useActiveBlocksuiteEditor(); - const editorRef = useRef(null); - - useEffect(() => { - if (editor) { - setActiveBlocksuiteEditor(editorRef.current); - } - }, [editor, setActiveBlocksuiteEditor]); - return ( ); });