Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: fix some issues

Adorian Doran1627f1e72784
diff --git a/apps/client/src/widgets/collections/board/column.tsx b/apps/client/src/widgets/collections/board/column.tsx
index 93af5edac1..bb396112d5 100644
--- a/apps/client/src/widgets/collections/board/column.tsx
+++ b/apps/client/src/widgets/collections/board/column.tsx
@@ -691,18 +691,27 @@ export function placeCard(card: HTMLElement, transform: string | null, atOnce: b
});
}
-/** Puts every suppressed transition back at once, for a board leaving the page. */
-export function settleCards() {
- if (restoring !== undefined) {
- cancelAnimationFrame(restoring);
- restoring = undefined;
- }
-
+/**
+ * Puts back at once the suppressed transitions of the cards one board holds, for a board leaving
+ * the page.
+ *
+ * Its own cards alone, and whatever has already left the page: another board can be part-way
+ * through a gesture, and the frame that would put its cards back is the same one.
+ */
+export function settleCards(container: HTMLElement | null) {
for (const held of settling) {
+ if (held.isConnected && !container?.contains(held)) {
+ continue;
+ }
+
held.style.removeProperty("transition");
+ settling.delete(held);
}
- settling.clear();
+ if (!settling.size && restoring !== undefined) {
+ cancelAnimationFrame(restoring);
+ restoring = undefined;
+ }
}
/** The cards whose transition is suppressed, waiting for the frame that puts it back. */
diff --git a/apps/client/src/widgets/collections/board/drag.spec.tsx b/apps/client/src/widgets/collections/board/drag.spec.tsx
index 1ea72cccc9..a3b43d4ae6 100644
--- a/apps/client/src/widgets/collections/board/drag.spec.tsx
+++ b/apps/client/src/widgets/collections/board/drag.spec.tsx
@@ -14,6 +14,7 @@ import { buildNote } from "../../../test/easy-froca";
import { TREE_CLIPBOARD_TYPE } from "../../note_tree";
import { ParentComponent } from "../../react/react_utils";
import BoardView, { BoardViewData } from ".";
+import { placeCard, settleCards } from "./column";
vi.mock("../../../services/branches", () => ({
default: {
@@ -873,6 +874,50 @@ describe("Board column reordering", () => {
}
});
+describe("a board leaving the page", () => {
+ /**
+ * Boards stay mounted across tabs and splits, and the frame that puts a suppressed transition
+ * back is one they share. A board being taken off the page settles its own cards alone.
+ */
+ it("puts back only the cards it holds, leaving another board's gesture alone", () => {
+ const [ leaving, staying ] = [ board(), board() ];
+
+ placeCard(leaving.card, "translateY(10px)", true);
+ placeCard(staying.card, "translateY(10px)", true);
+ expect([ leaving.card.style.transition, staying.card.style.transition ])
+ .toEqual([ "none", "none" ]);
+
+ settleCards(leaving.container);
+
+ expect(leaving.card.style.transition).toBe("");
+ expect(staying.card.style.transition).toBe("none");
+
+ settleCards(staying.container);
+ expect(staying.card.style.transition).toBe("");
+ for (const { container } of [ leaving, staying ]) container.remove();
+ });
+
+ /** A card taken off the page with its board has nothing left to animate. */
+ it("puts back a card that has already left the page, whichever board held it", () => {
+ const gone = board();
+ placeCard(gone.card, "translateY(10px)", true);
+ gone.container.remove();
+
+ settleCards(document.createElement("div"));
+
+ expect(gone.card.style.transition).toBe("");
+ });
+
+ function board() {
+ const container = document.createElement("div");
+ const card = document.createElement("div");
+ card.className = "board-note";
+ container.appendChild(card);
+ document.body.appendChild(container);
+ return { container, card };
+ }
+});
+
/** Every class the element wears at any point while `run` is going on. */
function classesWhile(element: HTMLElement, run: () => Promise<void>) {
return seenWhile(element, "class", () => element.classList, run);
diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsx
index 4f63954b2f..1e1242158a 100644
--- a/apps/client/src/widgets/collections/board/index.tsx
+++ b/apps/client/src/widgets/collections/board/index.tsx
@@ -788,12 +788,16 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
}, []);
// A board taken off the page leaves nothing of a gesture behind it to run in a later frame.
- useEffect(() => () => {
- if (stillFor.current !== undefined) {
- cancelAnimationFrame(stillFor.current);
- }
+ // The container is held from the mount: a ref is empty again by the time this is called.
+ useEffect(() => {
+ const container = containerRef.current;
+ return () => {
+ if (stillFor.current !== undefined) {
+ cancelAnimationFrame(stillFor.current);
+ }
- settleCards();
+ settleCards(container);
+ };
}, []);
const handleColumnDrop = useCallback((fromIndex: number, toIndex: number, animate = true) => {