Skip to content

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.

fix: cannot update a component while rendering a different component (#1907)

Himself652a2d682211f4
diff --git a/packages/component/src/components/block-suite-editor/index.tsx b/packages/component/src/components/block-suite-editor/index.tsx
index 093eec3de2..3725f46805 100644
--- a/packages/component/src/components/block-suite-editor/index.tsx
+++ b/packages/component/src/components/block-suite-editor/index.tsx
@@ -41,13 +41,17 @@ const BlockSuiteEditorImpl = (props: EditorProps): ReactElement => {
if (editor.mode !== props.mode) {
editor.mode = props.mode;
}
- if (editor.page !== props.page) {
- editor.page = props.page;
- if (page.root === null) {
- props.onInit(page, editor);
+
+ useEffect(() => {
+ if (editor.page !== props.page) {
+ editor.page = props.page;
+ if (page.root === null) {
+ props.onInit(page, editor);
+ }
+ props.onLoad?.(page, editor);
}
- props.onLoad?.(page, editor);
- }
+ }, [props.page, props.onInit, props.onLoad]);
+
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {