perf: use lazy load provider for IDB and SQLITE (#3351)

This commit is contained in:
Peng Xiao
2023-07-26 00:56:48 +08:00
committed by GitHub
parent e3f66d7e22
commit 20ee9d485d
25 changed files with 481 additions and 758 deletions

View File

@@ -26,6 +26,7 @@ export function useBlockSuitePagePreview(page: Page): Atom<string> {
const disposable = page.slots.yUpdated.on(() => {
set(getPagePreviewText(page));
});
set(getPagePreviewText(page));
return () => {
disposable.dispose();
};

View File

@@ -2,6 +2,7 @@ import { assertExists, DisposableGroup } from '@blocksuite/global/utils';
import type { Page, Workspace } from '@blocksuite/store';
import type { Atom } from 'jotai';
import { atom, useAtomValue } from 'jotai';
import { useEffect } from 'react';
const weakMap = new WeakMap<Workspace, Map<string, Atom<Page | null>>>();
@@ -51,5 +52,13 @@ export function useBlockSuiteWorkspacePage(
): Page | null {
const pageAtom = getAtom(blockSuiteWorkspace, pageId);
assertExists(pageAtom);
return useAtomValue(pageAtom);
const page = useAtomValue(pageAtom);
useEffect(() => {
if (!page?.loaded) {
page?.waitForLoaded().catch(console.error);
}
}, [page]);
return page;
}