Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: performance improvements

Adorian Doranac26426e0e70
diff --git a/apps/client/src/widgets/collections/board/column.tsx b/apps/client/src/widgets/collections/board/column.tsx
index 82fcc6baaf..246bd401b3 100644
--- a/apps/client/src/widgets/collections/board/column.tsx
+++ b/apps/client/src/widgets/collections/board/column.tsx
@@ -535,35 +535,28 @@ export default function Column({
style={scrollFade.style}
onWheel={handleScroll}
>
- {(columnItems ?? []).map(({ note, branch }, index) => {
- // The card being carried is out of the flow, so the gap stands in its own
- // place too: held still, which a touch does before it moves, that is where it
- // was picked up from.
- const showIndicatorBefore = dropIndex === index;
-
- return (
- <Fragment key={note.noteId}>
- {showIndicatorBefore && (
- <div className="board-drop-placeholder show" style={gapStyle} />
- )}
- {insertBefore?.branchId === branch.branchId && insertField}
- <Card
- api={api}
- note={note}
- branch={branch}
- column={column}
- index={index}
- statusAttribute={api.statusAttribute}
- isNew={note.noteId === createdNoteId}
- focusOnArrival={note.noteId === insertedNoteId}
- isDragging={draggedCard?.noteId === note.noteId}
- isEditing={branch.branchId === branchIdToEdit}
- onFocusCard={onFocusCard}
- onInsert={beginInsert}
- />
- </Fragment>
- );
- })}
+ {(columnItems ?? []).map(({ note, branch }, index) => (
+ <Fragment key={note.noteId}>
+ {dropIndex === index && (
+ <div className="board-drop-placeholder show" style={gapStyle} />
+ )}
+ {insertBefore?.branchId === branch.branchId && insertField}
+ <Card
+ api={api}
+ note={note}
+ branch={branch}
+ column={column}
+ index={index}
+ statusAttribute={api.statusAttribute}
+ isNew={note.noteId === createdNoteId}
+ focusOnArrival={note.noteId === insertedNoteId}
+ isDragging={draggedCard?.noteId === note.noteId}
+ isEditing={branch.branchId === branchIdToEdit}
+ onFocusCard={onFocusCard}
+ onInsert={beginInsert}
+ />
+ </Fragment>
+ ))}
{insertBefore && !insertBefore.branchId && insertField}
{dropIndex === (columnItems?.length ?? 0) && (
<div className="board-drop-placeholder show" style={gapStyle} />
diff --git a/apps/client/src/widgets/collections/board/drag.spec.tsx b/apps/client/src/widgets/collections/board/drag.spec.tsx
index 7d8b16bcda..c5e90fd7a3 100644
--- a/apps/client/src/widgets/collections/board/drag.spec.tsx
+++ b/apps/client/src/widgets/collections/board/drag.spec.tsx
@@ -521,7 +521,7 @@ describe("Board column reordering", () => {
// Watched rather than read afterwards: the frame that puts the transition back has run by
// the time the gesture returns.
expect(await classesWhile(board, () => carryColumn(columns[0], 280)))
- .toContain("board-columns-landing");
+ .toContain("board-landing");
});
it("eases the columns back where the drag is called off, having moved nothing", async () => {
@@ -530,7 +530,7 @@ describe("Board column reordering", () => {
// Let go where it started, which places the column back where it came from: the columns
// that stepped aside slide back, so the transition has to stay on.
expect(await classesWhile(board, () => carryColumn(columns[0], 20)))
- .not.toContain("board-columns-landing");
+ .not.toContain("board-landing");
});
it("puts the columns back once the gesture is over", async () => {
diff --git a/apps/client/src/widgets/collections/board/index.css b/apps/client/src/widgets/collections/board/index.css
index ca64222cfe..bd03bad546 100644
--- a/apps/client/src/widgets/collections/board/index.css
+++ b/apps/client/src/widgets/collections/board/index.css
@@ -923,13 +923,13 @@ body.mobile .column-drop-placeholder {
width var(--board-expand-duration) ease;
}
-/* The one frame the row is drawn in after a column is dropped. Each column already stands where
- that order puts it, carried there by the transform the drag wrote, so taking the transform off
- has nothing left to ease: given a transition it would carry the column a full width from a place
- it never stood in. Written against the selectors above, which it has to outweigh. */
-.board-view-container.board-columns-landing .board-column,
-.board-view-container.board-columns-landing .board-column.collapsed:not(.board-drag-preview),
-.board-view-container.board-columns-landing .board-column.quick-expand:not(.board-drag-preview) {
+/* The one frame the board is drawn in after something is dropped. Whatever was carried aside by a
+ transform already stands where the new order puts it, so taking the transform off has nothing
+ left to ease: given a transition it would carry the element a full width, or a card's height,
+ from a place it never stood in. Written against the selectors above, which it has to outweigh. */
+.board-view-container.board-landing .board-column,
+.board-view-container.board-landing .board-column.collapsed:not(.board-drag-preview),
+.board-view-container.board-landing .board-column.quick-expand:not(.board-drag-preview) {
transition: none;
}
diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsx
index b07856dd6f..5696b99154 100644
--- a/apps/client/src/widgets/collections/board/index.tsx
+++ b/apps/client/src/widgets/collections/board/index.tsx
@@ -655,14 +655,7 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
// where each column already stands where that order puts it. Eased to zero they
// would carry it a column's width from a place it never stood in, so the frame
// that takes them off runs without a transition.
- const container = containerRef.current;
- container?.classList.add("board-columns-landing");
-
- // Taken off a frame after the one that draws the row, not on it: a frame's
- // callbacks run before the styles it paints are worked out, so putting the
- // transition back in the first of them puts it back in time to be used.
- requestAnimationFrame(() => requestAnimationFrame(
- () => container?.classList.remove("board-columns-landing")));
+ land();
// Not animated either: the row puts the columns exactly where they already are.
handleColumnDrop(from, to, false);
}
@@ -757,6 +750,21 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
// The drag reports where the column landed among the ones on screen, which is not where it
// landed among them all once some are archived and hidden. Translated here so a reorder leaves
// every hidden column where it was rather than herding them to the end.
+ /**
+ * Draws the next frame without transitions.
+ *
+ * What a drag carried aside it carried by a transform, and the board is about to draw it where
+ * that transform already had it. Eased instead, each element would set off from a place it
+ * never stood in. Taken off a frame later than the one that draws it, since a frame's
+ * callbacks run before the styles it paints are worked out.
+ */
+ const land = useCallback(() => {
+ const container = containerRef.current;
+ container?.classList.add("board-landing");
+ requestAnimationFrame(() => requestAnimationFrame(
+ () => container?.classList.remove("board-landing")));
+ }, []);
+
const handleColumnDrop = useCallback((fromIndex: number, toIndex: number, animate = true) => {
if (animate) {
columnMovedUntil.current = Date.now() + FLIP_SETTLE_MS;