Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(client/collections): keep a superseded page load's failure quiet
Claude2d068a6c7184
diff --git a/apps/client/src/widgets/collections/Pagination.spec.tsx b/apps/client/src/widgets/collections/Pagination.spec.tsxindex 6bd3b36b47..0a45829e9f 100644--- a/apps/client/src/widgets/collections/Pagination.spec.tsx+++ b/apps/client/src/widgets/collections/Pagination.spec.tsx@@ -167,19 +167,28 @@ describe("usePagination", () => {}});- it("reports a failed note load instead of leaving the rejection unhandled", async () => {- const getNotesSpy = vi.spyOn(froca, "getNotes")- .mockRejectedValue(new Error("tree/load failed"));+ it("reports a failed note load, and stays quiet about a superseded one", async () => {+ // Hand out the reject side of each load, so the page-1 load can be failed after the flip+ // to page 2 has already superseded it.+ const pending: Array<(reason: Error) => void> = [];+ const getNotesSpy = vi.spyOn(froca, "getNotes").mockImplementation(() =>+ new Promise<FNote[]>((_resolve, reject) => pending.push(reject))+ );const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => {});try {const note = buildNote({ title: "Search", type: "search" });await mount(note, 10);- await settle();+ await act(async () => observed?.setPage?.(2));+ expect(pending).toHaveLength(2);++ const [ supersededLoad, currentLoad ] = pending;+ await act(async () => supersededLoad(new Error("tree/load failed")));+ expect(consoleSpy).not.toHaveBeenCalled();- // An unhandled rejection here fails the whole Vitest run, not just this test.- expect(consoleSpy).toHaveBeenCalled();+ await act(async () => currentLoad(new Error("tree/load failed")));+ expect(consoleSpy).toHaveBeenCalledTimes(1);+ expect(observed?.page).toBe(2);expect(observed?.pageNotes).toBeUndefined();- expect(observed?.page).toBe(1);} finally {consoleSpy.mockRestore();getNotesSpy.mockRestore();diff --git a/apps/client/src/widgets/collections/Pagination.tsx b/apps/client/src/widgets/collections/Pagination.tsxindex ec7fff7c61..340dd6b23c 100644--- a/apps/client/src/widgets/collections/Pagination.tsx+++ b/apps/client/src/widgets/collections/Pagination.tsx@@ -179,9 +179,14 @@ export function usePagination(setPageNotes(notes);}})- // froca.getNotes() rejects when its `tree/load` request fails. Report it and leave- // `pageNotes` as it stands, so the rejection reaches a handler.- .catch((e) => console.error(`Loading the notes of page ${effectivePage} failed`, e));+ // froca.getNotes() rejects when its `tree/load` request fails. The page keeps the notes+ // it already has, and a superseded load stays as quiet about failing as it does about+ // succeeding.+ .catch((e) => {+ if (!cancelled) {+ console.error(`Loading the notes of page ${effectivePage} failed`, e);+ }+ });return () => {cancelled = true;};