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
client/collections/board: performance improvements
Adorian Doranc92daeaa2cb2
diff --git a/apps/client/src/widgets/collections/board/column.tsx b/apps/client/src/widgets/collections/board/column.tsxindex a711b388ad..24d33eb50d 100644--- a/apps/client/src/widgets/collections/board/column.tsx+++ b/apps/client/src/widgets/collections/board/column.tsx@@ -306,6 +306,18 @@ export default function Column({* Unpainted rather than undrawn: the board focuses the card a keyboard open steps onto, and a* card that is not there yet is one it cannot hand focus to.*/+ /**+ * Whether the cards have been drawn, which they stay once they have been.+ *+ * A column collapsed when the board opens draws none of them, so a reader who keeps a long one+ * closed pays nothing for it. Past the first open they are held in the page and hidden rather+ * than taken out, closing costing a fraction of what building them again does.+ */+ const [ isDrawn, setIsDrawn ] = useState(!isCollapsed);+ if (!isDrawn && !isCollapsed) {+ setIsDrawn(true);+ }+const [ isExpanding, setIsExpanding ] = useState(false);const [ wasCollapsed, setWasCollapsed ] = useState(isCollapsed);if (wasCollapsed !== isCollapsed) {@@ -614,7 +626,7 @@ export default function Column({</>)}</h3>- {!isCollapsed && <div+ {isDrawn && <divref={contentRef}className={clsx("board-column-content", scrollFade.className)}style={scrollFade.style}diff --git a/apps/client/src/widgets/collections/board/drag_measure.spec.ts b/apps/client/src/widgets/collections/board/drag_measure.spec.tsindex 57cae87402..724ef2576e 100644--- a/apps/client/src/widgets/collections/board/drag_measure.spec.ts+++ b/apps/client/src/widgets/collections/board/drag_measure.spec.ts@@ -134,7 +134,22 @@ describe("measureBoard", () => {expect(areas.get("To Do")).toBe(board.querySelector(".board-column-content"));});- /** A collapsed column draws no card area at all. */+ /**+ * A strip holds its cards in the page without drawing any of them, so there is nothing in it+ * to place a card against and a card carried over one goes to the front of what it holds.+ */+ it("counts a collapsed column as holding no cards, whatever it holds", () => {+ const board = buildBoard({ cardCounts: [ 3, 1 ] });+ board.querySelector(".board-column")?.classList.add("collapsed");++ const { columns, areas } = measureBoard(board);++ expect(board.querySelectorAll(".board-column")[0].querySelectorAll(".board-note"))+ .toHaveLength(3);+ expect(columns[0].cards).toEqual([]);+ expect(areas.has("To Do")).toBe(false);+ });+it("counts a column with no card area as holding no cards", () => {const board = buildBoard();board.querySelector(".board-column-content")?.remove();diff --git a/apps/client/src/widgets/collections/board/drag_measure.ts b/apps/client/src/widgets/collections/board/drag_measure.tsindex 91eaafab52..fd4eae5899 100644--- a/apps/client/src/widgets/collections/board/drag_measure.ts+++ b/apps/client/src/widgets/collections/board/drag_measure.ts@@ -30,7 +30,11 @@ export function measureBoard(container: HTMLElement, withCards = true): BoardMeafor (const element of drawn) {const value = element.dataset.column ?? "";const rect = element.getBoundingClientRect();- const area = element.querySelector<HTMLElement>(".board-column-content");+ // A strip holds its cards in the page but draws none of them: they measure nothing, and a+ // card carried over one goes to the front of whatever it holds.+ const area = element.classList.contains("collapsed")+ ? null+ : element.querySelector<HTMLElement>(".board-column-content");if (area) {areas.set(value, area);diff --git a/apps/client/src/widgets/collections/board/index.css b/apps/client/src/widgets/collections/board/index.cssindex d5fc6dbfa1..c4ce56377b 100644--- a/apps/client/src/widgets/collections/board/index.css+++ b/apps/client/src/widgets/collections/board/index.css@@ -922,6 +922,13 @@ body.mobile .column-drop-placeholder {overflow: hidden;}+/* The cards stay in the page while the column is a strip, and this is what stops them being drawn.+ Taking them out instead costs a quarter of a second to close and over a second to open, both of+ which land on the frames the width is animating across. */+.board-view-container .board-column.collapsed > .board-column-content {+ content-visibility: hidden;+}+/* Width and not a transform: the columns beside it have to move with it. The copy being carried isleft out, or it would ease towards each frame's position instead of taking it: its `transition:none` above carries no more weight than this rule and stands above it in the file. */diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsxindex f27ba2f044..eb66738311 100644--- a/apps/client/src/widgets/collections/board/index.spec.tsx+++ b/apps/client/src/widgets/collections/board/index.spec.tsx@@ -271,8 +271,12 @@ describe("Collapsed board columns", () => {const isCollapsed = (container: HTMLElement, index: number) =>columnAt(container, index).classList.contains("collapsed");+ // How many cards the column draws. A strip holds its own in the page without drawing them,+ // which is what the reader sees and what the keyboard and a drag both go by.const cardCount = (container: HTMLElement, index: number) =>- columnAt(container, index).querySelectorAll(".board-note").length;+ isCollapsed(container, index)+ ? 0+ : columnAt(container, index).querySelectorAll(".board-note").length;/** Selects a column the way a click on it does, press and release included. */async function select(container: HTMLElement, index: number) {@@ -301,6 +305,8 @@ describe("Collapsed board columns", () => {expect(cardCount(mountPoint, 0)).toBe(0);// The count is what the strip reports in place of the cards.expect(columnAt(mountPoint, 0).querySelector(".counter-badge")?.textContent).toBe("2");+ // Never drawn at all, so a reader who keeps a long column closed pays nothing for it.+ expect(columnAt(mountPoint, 0).querySelector(".board-column-content")).toBeNull();// Every other column is untouched.expect(isCollapsed(mountPoint, 1)).toBe(false);@@ -317,6 +323,10 @@ describe("Collapsed board columns", () => {await select(mountPoint, 1);expect(isCollapsed(mountPoint, 0)).toBe(true);expect(cardCount(mountPoint, 0)).toBe(0);+ // Held in the page once they have been drawn once, the stylesheet keeping them off the+ // screen: taking them out again is what makes a column of thousands close in three frames.+ expect(columnAt(mountPoint, 0)+ .querySelectorAll(":scope > .board-column-content > .board-note")).toHaveLength(2);});/**diff --git a/apps/client/src/widgets/collections/board/keyboard.ts b/apps/client/src/widgets/collections/board/keyboard.tsindex 019f6a75ec..01d568c702 100644--- a/apps/client/src/widgets/collections/board/keyboard.ts+++ b/apps/client/src/widgets/collections/board/keyboard.ts@@ -578,5 +578,10 @@ function columnsOf(container: HTMLElement) {}function cardsOf(column: Element | undefined) {- return column ? [ ...column.querySelectorAll<HTMLElement>(".board-note") ] : [];+ // A strip holds its cards in the page but draws none of them, so it offers none to walk onto.+ if (!column || column.classList.contains("collapsed")) {+ return [];+ }++ return [ ...column.querySelectorAll<HTMLElement>(".board-note") ];}