diff --git a/desktop/src/components/Discussion.svelte b/desktop/src/components/Discussion.svelte
index 086dad86a..48aa21597 100644
--- a/desktop/src/components/Discussion.svelte
+++ b/desktop/src/components/Discussion.svelte
@@ -14,7 +14,7 @@
import partial from "lodash/partial";
import * as roles from "@app/lib/roles";
- import { mergeTimeline, timelineRuns } from "@app/lib/timelineRuns";
+ import { mergeTimeline, runKey, timelineRuns } from "@app/lib/timelineRuns";
import { authorForNodeId } from "@app/lib/utils";
import ExtendedTextarea from "@app/components/ExtendedTextarea.svelte";
@@ -182,7 +182,7 @@
0}>
- {#each runs as run, runIndex (runIndex)}
+ {#each runs as run (runKey(run))}
{#if run.kind === "thread"}
- {#each replies as reply}
+ {#each replies as reply (reply.id)}
diff --git a/desktop/src/lib/timelineRuns.ts b/desktop/src/lib/timelineRuns.ts
index 970a52271..f6908b296 100644
--- a/desktop/src/lib/timelineRuns.ts
+++ b/desktop/src/lib/timelineRuns.ts
@@ -114,3 +114,10 @@ export function timelineRuns
(
}
return result;
}
+
+/// A run's identity across updates, so that a thread keeps its open reply
+/// draft when comments are added or removed around it.
+export function runKey(run: Run): string {
+ if (run.kind === "group") return `group:${run.entries[0].key}`;
+ return `${run.kind}:${run.entry.key}`;
+}
diff --git a/desktop/tests/unit/timelineRuns.test.ts b/desktop/tests/unit/timelineRuns.test.ts
index c450d02fe..57321d19b 100644
--- a/desktop/tests/unit/timelineRuns.test.ts
+++ b/desktop/tests/unit/timelineRuns.test.ts
@@ -4,7 +4,7 @@ import type { Thread } from "@bindings/cob/thread/Thread";
import { describe, expect, test } from "vitest";
import type { Run, TimelineEntry } from "@app/lib/timelineRuns";
-import { mergeTimeline, timelineRuns } from "@app/lib/timelineRuns";
+import { mergeTimeline, runKey, timelineRuns } from "@app/lib/timelineRuns";
import { author, comment } from "./support/cobs";
@@ -148,3 +148,31 @@ describe("timelineRuns", () => {
).toEqual(["x", "y"]);
});
});
+
+describe("runKey", () => {
+ test("a thread keeps its key when a run before it goes away", () => {
+ const authorOf = (data: Data) => data.by;
+ const before = timelineRuns(
+ [threadEntry("t1", alice), activity("a1", bob), threadEntry("t2", bob)],
+ authorOf,
+ );
+ const after = timelineRuns([threadEntry("t2", bob)], authorOf);
+
+ expect(runKey(after[0])).toBe(runKey(before[2]));
+ });
+
+ test("keys are unique within a timeline", () => {
+ const runs = timelineRuns(
+ [
+ activity("x", alice),
+ threadEntry("x", bob),
+ activity("y", bob),
+ activity("z", bob),
+ ],
+ (data: Data) => data.by,
+ );
+ const keys = runs.map(runKey);
+
+ expect(new Set(keys).size).toBe(keys.length);
+ });
+});