mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
perf: use lazy load provider for IDB and SQLITE (#3351)
This commit is contained in:
@@ -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();
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user