fix(core): sidebar extension sometimes not show (#5513)

This commit is contained in:
Peng Xiao 2024-01-05 13:17:02 +00:00
parent b0716ae721
commit b86a5a2830
No known key found for this signature in database
GPG Key ID: 23F23D9E8B3971ED

View File

@ -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<AffineEditorContainer>();
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<AffineEditorContainer | null>(null);
useEffect(() => {
if (editor) {
setActiveBlocksuiteEditor(editorRef.current);
}
}, [editor, setActiveBlocksuiteEditor]);
return (
<Editor
className={clsx(styles.editor, {
@ -149,7 +132,6 @@ const PageDetailEditorMain = memo(function PageDetailEditorMain({
onModeChange={setEditorMode}
defaultSelectedBlockId={blockId}
onLoadEditor={onLoadEditor}
ref={editorRef}
/>
);
});