Skip to content

Build your personal knowledge base with Trilium Notes

fix(board): key the fragment the card list actually contains

Elian Doran8e804b4940b4
diff --git a/apps/client/src/services/debug_perf.ts b/apps/client/src/services/debug_perf.ts
index 1d0164554f..ee66cc08a1 100644
--- a/apps/client/src/services/debug_perf.ts
+++ b/apps/client/src/services/debug_perf.ts
@@ -22,9 +22,8 @@ interface Counter {
maxMs: number;
}
-const NOOP = () => {
- /* recording is off */
-};
+/** Closing a span that was never opened, because recording is off. */
+const NOOP_SPAN = () => 0;
/**
* A main-thread block this long counts as a stall. Matches the Long Tasks API's own threshold, so
@@ -44,19 +43,24 @@ export function isPerfRecording() {
/**
* Opens a span. Call the returned function to close it, which records the elapsed time under
- * `label` and emits a matching `performance.measure()` entry.
+ * `label`, emits a matching `performance.measure()` entry, and returns the elapsed milliseconds.
+ *
+ * Prefer that returned number over the STALL lines for "what did this one operation cost": a stall
+ * is the gap between animation frames, so on a saturated main thread it reports the whole
+ * contiguous busy period and lumps however many operations fell inside it together.
*
* Returns a no-op when recording is off, so the caller does not need to branch.
*/
-export function perfSpan(label: string): () => void {
+export function perfSpan(label: string): () => number {
if (!enabled) {
- return NOOP;
+ return NOOP_SPAN;
}
const start = performance.now();
return () => {
const end = performance.now();
- record(label, end - start);
+ const duration = end - start;
+ record(label, duration);
try {
// Same clock as performance.now(), so the span lands where it actually happened.
@@ -64,6 +68,8 @@ export function perfSpan(label: string): () => void {
} catch (e) {
// A measure() that the browser rejects must not take the instrumented code down.
}
+
+ return duration;
};
}
diff --git a/apps/client/src/widgets/collections/board/column.tsx b/apps/client/src/widgets/collections/board/column.tsx
index f014b67bfb..4ef37574f1 100644
--- a/apps/client/src/widgets/collections/board/column.tsx
+++ b/apps/client/src/widgets/collections/board/column.tsx
@@ -1,18 +1,20 @@
+import { Fragment } from "preact";
import { useCallback, useContext, useEffect, useRef, useState } from "preact/hooks";
+import { JSX } from "preact/jsx-runtime";
+
import FBranch from "../../../entities/fbranch";
import FNote from "../../../entities/fnote";
-import { BoardViewContext, TitleEditor } from ".";
-import branches from "../../../services/branches";
-import { openColumnContextMenu } from "./context_menu";
import { ContextMenuEvent } from "../../../menus/context_menu";
-import Icon from "../../react/Icon";
-import { t } from "../../../services/i18n";
-import BoardApi from "./api";
-import Card, { CARD_CLIPBOARD_TYPE, CardDragData } from "./card";
-import { JSX } from "preact/jsx-runtime";
+import branches from "../../../services/branches";
import froca from "../../../services/froca";
+import { t } from "../../../services/i18n";
import { DragData, TREE_CLIPBOARD_TYPE } from "../../note_tree";
+import Icon from "../../react/Icon";
import NoteLink from "../../react/NoteLink";
+import { BoardViewContext, TitleEditor } from ".";
+import BoardApi from "./api";
+import Card, { CARD_CLIPBOARD_TYPE, CardDragData } from "./card";
+import { openColumnContextMenu } from "./context_menu";
interface DragContext {
column: string;
@@ -108,8 +110,8 @@ export default function Column({
<>
<span className="title">
{isInRelationMode
- ? <NoteLink notePath={column} showNoteIcon />
- : column}
+ ? <NoteLink notePath={column} showNoteIcon />
+ : column}
</span>
<span className="counter-badge">{columnItems?.length ?? 0}</span>
<div className="spacer" />
@@ -136,12 +138,13 @@ export default function Column({
draggedCard?.noteId !== note.noteId;
return (
- <>
+ // Keyed on the fragment, since the fragment is what this map contributes to
+ // the child array; on the <Card> inside it the key identifies nothing.
+ <Fragment key={note.noteId}>
{showIndicatorBefore && (
<div className="board-drop-placeholder show" />
)}
<Card
- key={note.noteId}
api={api}
note={note}
branch={branch}
@@ -149,7 +152,7 @@ export default function Column({
index={index}
isDragging={draggedCard?.noteId === note.noteId}
/>
- </>
+ </Fragment>
);
})}
{dropPosition?.column === column && dropPosition.index === (columnItems?.length ?? 0) && (
@@ -159,7 +162,7 @@ export default function Column({
<AddNewItem api={api} column={column} />
</div>
</div>
- )
+ );
}
function AddNewItem({ column, api }: { column: string, api: BoardApi }) {
diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsx
index 186bb534d1..99727ff2a5 100644
--- a/apps/client/src/widgets/collections/board/index.tsx
+++ b/apps/client/src/widgets/collections/board/index.tsx
@@ -152,8 +152,17 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
endMatch();
if (reason) {
- perfLog("board.refresh", { reason, changedNotes: loadResults.getNoteIds().length, cards: noteIds.length });
- renderSpanRef.current = perfSpan(`board.refreshToPaint[${reason}]`);
+ // Logged when the redraw lands rather than when it starts, so each line carries its own
+ // cost. A STALL line cannot answer that on a saturated main thread -- it spans every
+ // redraw that fell inside one contiguous busy period.
+ const endRefresh = perfSpan(`board.refreshToPaint[${reason}]`);
+ renderSpanRef.current = () => perfLog("board.refreshToPaint", {
+ reason,
+ ms: Math.round(endRefresh()),
+ cards: noteIds.length,
+ changedNotes: loadResults.getNoteIds().length
+ });
+
refresh();
}
});