feat: add suspense fallback for editor (#2278)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
import { style } from '@vanilla-extract/css';
|
||||||
|
|
||||||
|
export const blockSuiteEditorStyle = style({
|
||||||
|
padding: '0 1rem',
|
||||||
|
});
|
||||||
@@ -3,12 +3,15 @@ import type { BlockHub } from '@blocksuite/blocks';
|
|||||||
import type { EditorContainer } from '@blocksuite/editor';
|
import type { EditorContainer } from '@blocksuite/editor';
|
||||||
import { assertExists } from '@blocksuite/global/utils';
|
import { assertExists } from '@blocksuite/global/utils';
|
||||||
import type { Page } from '@blocksuite/store';
|
import type { Page } from '@blocksuite/store';
|
||||||
|
import { Skeleton } from '@mui/material';
|
||||||
import { useAtomValue } from 'jotai';
|
import { useAtomValue } from 'jotai';
|
||||||
import type { CSSProperties, ReactElement } from 'react';
|
import type { CSSProperties, ReactElement } from 'react';
|
||||||
import { memo, Suspense, useCallback, useEffect, useRef } from 'react';
|
import { memo, Suspense, useCallback, useEffect, useRef } from 'react';
|
||||||
import type { FallbackProps } from 'react-error-boundary';
|
import type { FallbackProps } from 'react-error-boundary';
|
||||||
import { ErrorBoundary } from 'react-error-boundary';
|
import { ErrorBoundary } from 'react-error-boundary';
|
||||||
|
|
||||||
|
import { blockSuiteEditorStyle } from './index.css';
|
||||||
|
|
||||||
export type EditorProps = {
|
export type EditorProps = {
|
||||||
page: Page;
|
page: Page;
|
||||||
mode: 'page' | 'edgeless';
|
mode: 'page' | 'edgeless';
|
||||||
@@ -122,6 +125,18 @@ const BlockSuiteErrorFallback = (
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const BlockSuiteFallback = memo(function BlockSuiteFallback() {
|
||||||
|
return (
|
||||||
|
<div className={blockSuiteEditorStyle}>
|
||||||
|
<Skeleton animation="wave" height={60} />
|
||||||
|
{Array.from({ length: 10 }).map((_, index) => (
|
||||||
|
<Skeleton animation="wave" height={30} key={index} />
|
||||||
|
))}
|
||||||
|
<Skeleton animation="wave" height={30} width="40%" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
export const BlockSuiteEditor = memo(function BlockSuiteEditor(
|
export const BlockSuiteEditor = memo(function BlockSuiteEditor(
|
||||||
props: EditorProps & ErrorBoundaryProps
|
props: EditorProps & ErrorBoundaryProps
|
||||||
): ReactElement {
|
): ReactElement {
|
||||||
@@ -134,7 +149,7 @@ export const BlockSuiteEditor = memo(function BlockSuiteEditor(
|
|||||||
[props.onReset]
|
[props.onReset]
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<Suspense fallback={null}>
|
<Suspense fallback={<BlockSuiteFallback />}>
|
||||||
<BlockSuiteEditorImpl {...props} />
|
<BlockSuiteEditorImpl {...props} />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
|
|||||||
Reference in New Issue
Block a user