fix(hooks): missing page preview and references (#4863)

This commit is contained in:
EYHN
2023-11-09 16:59:36 +08:00
committed by GitHub
parent 248fb1fa69
commit e3e0553c56
2 changed files with 21 additions and 10 deletions

View File

@@ -25,14 +25,19 @@ export function useBlockSuitePagePreview(page: Page | null): Atom<string> {
} else if (weakMap.has(page)) { } else if (weakMap.has(page)) {
return weakMap.get(page) as Atom<string>; return weakMap.get(page) as Atom<string>;
} else { } else {
const baseAtom = atom<string>(getPagePreviewText(page)); const baseAtom = atom<string>('');
baseAtom.onMount = set => { baseAtom.onMount = set => {
const disposable = page.slots.yUpdated.on(() => { const disposables = [
page.slots.ready.on(() => {
set(getPagePreviewText(page)); set(getPagePreviewText(page));
}); }),
page.slots.yUpdated.on(() => {
set(getPagePreviewText(page));
}),
];
set(getPagePreviewText(page)); set(getPagePreviewText(page));
return () => { return () => {
disposable.dispose(); disposables.forEach(disposable => disposable.dispose());
}; };
}; };
weakMap.set(page, baseAtom); weakMap.set(page, baseAtom);

View File

@@ -19,13 +19,19 @@ const getPageReferencesAtom = (page: Page | null) => {
} }
if (!weakMap.has(page)) { if (!weakMap.has(page)) {
const baseAtom = atom<string[]>(getPageReferences(page)); const baseAtom = atom<string[]>([]);
baseAtom.onMount = set => { baseAtom.onMount = set => {
const dispose = page.slots.yUpdated.on(() => { const disposables = [
page.slots.ready.on(() => {
set(getPageReferences(page));
}),
page.slots.yUpdated.on(() => {
set(getPageReferences(page));
}),
];
set(getPageReferences(page)); set(getPageReferences(page));
});
return () => { return () => {
dispose.dispose(); disposables.forEach(disposable => disposable.dispose());
}; };
}; };
weakMap.set(page, baseAtom); weakMap.set(page, baseAtom);