mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-11-24 09:46:58 +03:00
fix: reference page crash for deleted items (#3835)
This commit is contained in:
parent
ba676eb937
commit
bd826bb7f9
@ -29,7 +29,11 @@ export const ReferencePage = ({
|
||||
const icon = setting?.mode === 'edgeless' ? <EdgelessIcon /> : <PageIcon />;
|
||||
const references = useBlockSuitePageReferences(workspace, pageId);
|
||||
const referencesToShow = useMemo(() => {
|
||||
return [...new Set(references.filter(ref => !metaMapping[ref]?.trash))];
|
||||
return [
|
||||
...new Set(
|
||||
references.filter(ref => metaMapping[ref] && !metaMapping[ref]?.trash)
|
||||
),
|
||||
];
|
||||
}, [references, metaMapping]);
|
||||
const [collapsed, setCollapsed] = useState(true);
|
||||
const collapsible = referencesToShow.length > 0;
|
||||
|
@ -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));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user