fix: wrap React.lazy with Suspense (#1915)

This commit is contained in:
Himself65
2023-04-12 22:33:31 -05:00
committed by GitHub
parent 2bcda973d3
commit 6180a4c3cb
8 changed files with 138 additions and 120 deletions

View File

@@ -5,7 +5,7 @@ import { useBlockSuiteWorkspacePageTitle } from '@toeverything/hooks/use-blocksu
import { useAtomValue, useSetAtom } from 'jotai';
import Head from 'next/head';
import type React from 'react';
import { lazy, startTransition, useCallback } from 'react';
import { lazy, startTransition, Suspense, useCallback } from 'react';
import { currentEditorAtom, workspacePreferredModeAtom } from '../atoms';
import { usePageMeta } from '../hooks/use-page-meta';
@@ -64,32 +64,34 @@ export const PageDetailEditor: React.FC<PageDetailEditorProps> = ({
>
{header}
</WorkspaceHeader>
<Editor
style={{
height: 'calc(100% - 52px)',
}}
key={pageId}
mode={isPublic ? 'page' : currentMode}
page={page}
onInit={useCallback(
(page: Page, editor: Readonly<EditorContainer>) => {
startTransition(() => {
setEditor(editor);
});
onInit(page, editor);
},
[onInit, setEditor]
)}
onLoad={useCallback(
(page: Page, editor: EditorContainer) => {
startTransition(() => {
setEditor(editor);
});
onLoad?.(page, editor);
},
[onLoad, setEditor]
)}
/>
<Suspense>
<Editor
style={{
height: 'calc(100% - 52px)',
}}
key={pageId}
mode={isPublic ? 'page' : currentMode}
page={page}
onInit={useCallback(
(page: Page, editor: Readonly<EditorContainer>) => {
startTransition(() => {
setEditor(editor);
});
onInit(page, editor);
},
[onInit, setEditor]
)}
onLoad={useCallback(
(page: Page, editor: EditorContainer) => {
startTransition(() => {
setEditor(editor);
});
onLoad?.(page, editor);
},
[onLoad, setEditor]
)}
/>
</Suspense>
</>
);
};