mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 13:25:12 +00:00
fix: reference page crash for deleted items (#3835)
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user