There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
fix(core): avoid multiple append right sidebar tab lit component (#9806)
L-Sund2bde09ef630
diff --git a/packages/frontend/core/src/desktop/pages/workspace/detail-page/tabs/frame.tsx b/packages/frontend/core/src/desktop/pages/workspace/detail-page/tabs/frame.tsxindex 6ca62948e7..baf94ea5cb 100644--- a/packages/frontend/core/src/desktop/pages/workspace/detail-page/tabs/frame.tsx+++ b/packages/frontend/core/src/desktop/pages/workspace/detail-page/tabs/frame.tsx@@ -1,7 +1,6 @@-import { assertExists } from '@blocksuite/affine/global/utils';import type { AffineEditorContainer } from '@blocksuite/affine/presets';import { FramePanel } from '@blocksuite/affine/presets';-import { useCallback, useRef } from 'react';+import { useCallback, useEffect, useRef } from 'react';import * as styles from './frame.css';@@ -13,25 +12,23 @@ export const EditorFramePanel = ({}) => {const framePanelRef = useRef<FramePanel | null>(null);- const onRefChange = useCallback((container: HTMLDivElement | null) => {- if (container) {- assertExists(framePanelRef.current, 'frame panel should be initialized');- container.append(framePanelRef.current);- }- }, []);-- if (!editor) {- return;- }+ const onRefChange = useCallback(+ (container: HTMLDivElement | null) => {+ if (editor?.host && container && container.children.length === 0) {+ framePanelRef.current = new FramePanel();+ framePanelRef.current.host = editor.host;+ framePanelRef.current.fitPadding = [20, 20, 20, 20];+ container.append(framePanelRef.current);+ }+ },+ [editor?.host]+ );- if (!framePanelRef.current) {- framePanelRef.current = new FramePanel();- }-- if (editor.host !== framePanelRef.current?.host && editor.host) {- (framePanelRef.current as FramePanel).host = editor.host;- (framePanelRef.current as FramePanel).fitPadding = [20, 20, 20, 20];- }+ useEffect(() => {+ if (editor?.host && framePanelRef.current) {+ framePanelRef.current.host = editor.host;+ }+ }, [editor?.host]);return <div className={styles.root} ref={onRefChange} />;};diff --git a/packages/frontend/core/src/desktop/pages/workspace/detail-page/tabs/outline.tsx b/packages/frontend/core/src/desktop/pages/workspace/detail-page/tabs/outline.tsxindex f161959486..3c20399fbc 100644--- a/packages/frontend/core/src/desktop/pages/workspace/detail-page/tabs/outline.tsx+++ b/packages/frontend/core/src/desktop/pages/workspace/detail-page/tabs/outline.tsx@@ -1,6 +1,6 @@import type { AffineEditorContainer } from '@blocksuite/affine/presets';import { OutlinePanel } from '@blocksuite/affine/presets';-import { useCallback, useRef } from 'react';+import { useCallback, useEffect, useRef } from 'react';import * as styles from './outline.css';@@ -12,28 +12,23 @@ export const EditorOutlinePanel = ({}) => {const outlinePanelRef = useRef<OutlinePanel | null>(null);- const onRefChange = useCallback((container: HTMLDivElement | null) => {- if (container) {- if (outlinePanelRef.current === null) {- console.error('outline panel should be initialized');- return;+ const onRefChange = useCallback(+ (container: HTMLDivElement | null) => {+ if (container && editor && container.children.length === 0) {+ outlinePanelRef.current = new OutlinePanel();+ outlinePanelRef.current.editor = editor;+ outlinePanelRef.current.fitPadding = [20, 20, 20, 20];+ container.append(outlinePanelRef.current);}- container.append(outlinePanelRef.current);- }- }, []);-- if (!editor) {- return;- }+ },+ [editor]+ );- if (!outlinePanelRef.current) {- outlinePanelRef.current = new OutlinePanel();- }-- if (editor !== outlinePanelRef.current?.editor) {- (outlinePanelRef.current as OutlinePanel).editor = editor;- (outlinePanelRef.current as OutlinePanel).fitPadding = [20, 20, 20, 20];- }+ useEffect(() => {+ if (editor && outlinePanelRef.current) {+ outlinePanelRef.current.editor = editor;+ }+ }, [editor]);return <div className={styles.root} ref={onRefChange} />;};