fix: reference page crash for deleted items (#3835)

This commit is contained in:
Peng Xiao
2023-08-19 02:52:09 +08:00
committed by GitHub
parent ba676eb937
commit bd826bb7f9
2 changed files with 10 additions and 4 deletions

View File

@@ -1,4 +1,3 @@
import { assertExists } from '@blocksuite/global/utils';
import type { Page, Workspace } from '@blocksuite/store';
import { type Atom, atom, useAtomValue } from 'jotai';
@@ -14,7 +13,11 @@ function getPageReferences(page: Page): string[] {
.filter(Boolean);
}
const getPageReferencesAtom = (page: Page) => {
const getPageReferencesAtom = (page: Page | null) => {
if (!page) {
return atom([]);
}
if (!weakMap.has(page)) {
const baseAtom = atom<string[]>(getPageReferences(page));
baseAtom.onMount = set => {
@@ -35,6 +38,5 @@ export function useBlockSuitePageReferences(
pageId: string
): string[] {
const page = useBlockSuiteWorkspacePage(blockSuiteWorkspace, pageId);
assertExists(page);
return useAtomValue(getPageReferencesAtom(page));
}