fix: wrap React.lazy with Suspense (#1915)
This commit is contained in:
@@ -5,7 +5,7 @@ import { useBlockSuiteWorkspacePageTitle } from '@toeverything/hooks/use-blocksu
|
|||||||
import { useAtomValue, useSetAtom } from 'jotai';
|
import { useAtomValue, useSetAtom } from 'jotai';
|
||||||
import Head from 'next/head';
|
import Head from 'next/head';
|
||||||
import type React from 'react';
|
import type React from 'react';
|
||||||
import { lazy, startTransition, useCallback } from 'react';
|
import { lazy, startTransition, Suspense, useCallback } from 'react';
|
||||||
|
|
||||||
import { currentEditorAtom, workspacePreferredModeAtom } from '../atoms';
|
import { currentEditorAtom, workspacePreferredModeAtom } from '../atoms';
|
||||||
import { usePageMeta } from '../hooks/use-page-meta';
|
import { usePageMeta } from '../hooks/use-page-meta';
|
||||||
@@ -64,6 +64,7 @@ export const PageDetailEditor: React.FC<PageDetailEditorProps> = ({
|
|||||||
>
|
>
|
||||||
{header}
|
{header}
|
||||||
</WorkspaceHeader>
|
</WorkspaceHeader>
|
||||||
|
<Suspense>
|
||||||
<Editor
|
<Editor
|
||||||
style={{
|
style={{
|
||||||
height: 'calc(100% - 52px)',
|
height: 'calc(100% - 52px)',
|
||||||
@@ -90,6 +91,7 @@ export const PageDetailEditor: React.FC<PageDetailEditorProps> = ({
|
|||||||
[onLoad, setEditor]
|
[onLoad, setEditor]
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
</Suspense>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { MuiFade, Tooltip } from '@affine/component';
|
|||||||
import { config } from '@affine/env';
|
import { config } from '@affine/env';
|
||||||
import { useTranslation } from '@affine/i18n';
|
import { useTranslation } from '@affine/i18n';
|
||||||
import { CloseIcon, NewIcon } from '@blocksuite/icons';
|
import { CloseIcon, NewIcon } from '@blocksuite/icons';
|
||||||
import { lazy, useState } from 'react';
|
import { lazy, Suspense, useState } from 'react';
|
||||||
|
|
||||||
import { ShortcutsModal } from '../shortcuts-modal';
|
import { ShortcutsModal } from '../shortcuts-modal';
|
||||||
import { ContactIcon, HelpIcon, KeyboardIcon } from './Icons';
|
import { ContactIcon, HelpIcon, KeyboardIcon } from './Icons';
|
||||||
@@ -113,11 +113,13 @@ export const HelpIsland = ({
|
|||||||
</StyledTriggerWrapper>
|
</StyledTriggerWrapper>
|
||||||
</MuiFade>
|
</MuiFade>
|
||||||
</StyledIsland>
|
</StyledIsland>
|
||||||
|
<Suspense>
|
||||||
<ContactModal
|
<ContactModal
|
||||||
open={open}
|
open={open}
|
||||||
onClose={() => setOpen(false)}
|
onClose={() => setOpen(false)}
|
||||||
logoSrc="/imgs/affine-text-logo.png"
|
logoSrc="/imgs/affine-text-logo.png"
|
||||||
/>
|
/>
|
||||||
|
</Suspense>
|
||||||
<ShortcutsModal
|
<ShortcutsModal
|
||||||
open={openShortCut}
|
open={openShortCut}
|
||||||
onClose={() => setOpenShortCut(false)}
|
onClose={() => setOpenShortCut(false)}
|
||||||
|
|||||||
@@ -69,12 +69,14 @@ export const PublicQuickSearch: FC = () => {
|
|||||||
openQuickSearchModalAtom
|
openQuickSearchModalAtom
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
|
<Suspense>
|
||||||
<QuickSearchModal
|
<QuickSearchModal
|
||||||
blockSuiteWorkspace={publicWorkspace.blockSuiteWorkspace}
|
blockSuiteWorkspace={publicWorkspace.blockSuiteWorkspace}
|
||||||
open={openQuickSearchModal}
|
open={openQuickSearchModal}
|
||||||
setOpen={setOpenQuickSearchModalAtom}
|
setOpen={setOpenQuickSearchModalAtom}
|
||||||
router={router}
|
router={router}
|
||||||
/>
|
/>
|
||||||
|
</Suspense>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -28,12 +28,14 @@ export const PublicQuickSearch: React.FC = () => {
|
|||||||
openQuickSearchModalAtom
|
openQuickSearchModalAtom
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
|
<Suspense>
|
||||||
<QuickSearchModal
|
<QuickSearchModal
|
||||||
blockSuiteWorkspace={publicWorkspace.blockSuiteWorkspace}
|
blockSuiteWorkspace={publicWorkspace.blockSuiteWorkspace}
|
||||||
open={openQuickSearchModal}
|
open={openQuickSearchModal}
|
||||||
setOpen={setOpenQuickSearchModalAtom}
|
setOpen={setOpenQuickSearchModalAtom}
|
||||||
router={router}
|
router={router}
|
||||||
/>
|
/>
|
||||||
|
</Suspense>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { NoSsr } from '@mui/material';
|
import { NoSsr } from '@mui/material';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import { lazy } from 'react';
|
import { lazy, Suspense } from 'react';
|
||||||
|
|
||||||
import { StyledPage, StyledWrapper } from '../../layouts/styles';
|
import { StyledPage, StyledWrapper } from '../../layouts/styles';
|
||||||
import type { NextPageWithLayout } from '../../shared';
|
import type { NextPageWithLayout } from '../../shared';
|
||||||
@@ -26,7 +26,9 @@ const InitPagePage: NextPageWithLayout = () => {
|
|||||||
return (
|
return (
|
||||||
<StyledPage>
|
<StyledPage>
|
||||||
<StyledWrapper>
|
<StyledWrapper>
|
||||||
|
<Suspense>
|
||||||
<Editor onInit={initPage} testType={testType} />
|
<Editor onInit={initPage} testType={testType} />
|
||||||
|
</Suspense>
|
||||||
<div id="toolWrapper" />
|
<div id="toolWrapper" />
|
||||||
</StyledWrapper>
|
</StyledWrapper>
|
||||||
</StyledPage>
|
</StyledPage>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
} from '@affine/workspace/affine/login';
|
} from '@affine/workspace/affine/login';
|
||||||
import { useAtom } from 'jotai';
|
import { useAtom } from 'jotai';
|
||||||
import type { NextPage } from 'next';
|
import type { NextPage } from 'next';
|
||||||
import { lazy, useMemo } from 'react';
|
import { lazy, Suspense, useMemo } from 'react';
|
||||||
|
|
||||||
import { toast } from '../../utils';
|
import { toast } from '../../utils';
|
||||||
|
|
||||||
@@ -91,10 +91,12 @@ const LoginDevPage: NextPage = () => {
|
|||||||
>
|
>
|
||||||
Check Permission
|
Check Permission
|
||||||
</Button>
|
</Button>
|
||||||
|
<Suspense>
|
||||||
<Viewer
|
<Viewer
|
||||||
theme={useTheme().resolvedTheme === 'light' ? 'light' : 'dark'}
|
theme={useTheme().resolvedTheme === 'light' ? 'light' : 'dark'}
|
||||||
value={user}
|
value={user}
|
||||||
/>
|
/>
|
||||||
|
</Suspense>
|
||||||
</StyledWrapper>
|
</StyledWrapper>
|
||||||
</StyledPage>
|
</StyledPage>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -71,10 +71,12 @@ const ListPageInner: React.FC<{
|
|||||||
<SearchIcon />
|
<SearchIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</NavContainer>
|
</NavContainer>
|
||||||
|
<Suspense>
|
||||||
<BlockSuitePublicPageList
|
<BlockSuitePublicPageList
|
||||||
onOpenPage={handleClickPage}
|
onOpenPage={handleClickPage}
|
||||||
blockSuiteWorkspace={blockSuiteWorkspace}
|
blockSuiteWorkspace={blockSuiteWorkspace}
|
||||||
/>
|
/>
|
||||||
|
</Suspense>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { arrayMove } from '@dnd-kit/sortable';
|
|||||||
import { useAtom, useAtomValue, useSetAtom } from 'jotai';
|
import { useAtom, useAtomValue, useSetAtom } from 'jotai';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import type React from 'react';
|
import type React from 'react';
|
||||||
import { lazy, useCallback, useTransition } from 'react';
|
import { lazy, Suspense, useCallback, useTransition } from 'react';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
currentWorkspaceIdAtom,
|
currentWorkspaceIdAtom,
|
||||||
@@ -49,6 +49,7 @@ export function Modals() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
<Suspense>
|
||||||
<WorkspaceListModal
|
<WorkspaceListModal
|
||||||
disabled={transitioning}
|
disabled={transitioning}
|
||||||
user={user}
|
user={user}
|
||||||
@@ -92,6 +93,8 @@ export function Modals() {
|
|||||||
setOpenCreateWorkspaceModal(true);
|
setOpenCreateWorkspaceModal(true);
|
||||||
}, [setOpenCreateWorkspaceModal])}
|
}, [setOpenCreateWorkspaceModal])}
|
||||||
/>
|
/>
|
||||||
|
</Suspense>
|
||||||
|
<Suspense>
|
||||||
<CreateWorkspaceModal
|
<CreateWorkspaceModal
|
||||||
open={openCreateWorkspaceModal}
|
open={openCreateWorkspaceModal}
|
||||||
onClose={useCallback(() => {
|
onClose={useCallback(() => {
|
||||||
@@ -114,6 +117,7 @@ export function Modals() {
|
|||||||
]
|
]
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
</Suspense>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user