fix(desktop): carry head aux deletion closure into thread panel

Address the P1 review comment on #6887: headAuxEventsFromChannelWindow
copied only aux events (#e-referencing the head), but a kind:5/9005 that
deletes one of those edits/reactions references the OVERLAY's id, not the
head's — so it was dropped. formatTimelineMessages skips an edit only when
the edit's own id is in deletedEventIds, so the thread panel resurrected a
deleted edit/reaction that the main timeline correctly hides, until the
async thread-aux backfill landed (or permanently if it failed).

Copy channel-window deletions that target the selected head aux events too,
mirroring the closure the aux-backfill paths build
(mergeAuxEventsWithDeletionBackfill). The existing replyEvents dedup covers
the copied deletions as well.

Also address the screenshot-timing comment: call waitForAnimations(page)
before the capture in thread-head-stale-edit.spec.ts, as AGENTS.md requires
before every Playwright screenshot.

Tests:
- Two new red/green unit cases in independentThreadPanel.test.mjs (deleted
  edit and deleted reaction on the head). Verified red pre-fix (2 fail),
  green post-fix.
- Full desktop unit suite: 5564 pass / 0 fail. biome + tsc clean.
- e2e thread-head-stale-edit.spec.ts: green; screenshot confirms the thread
  head shows the edited body while thread aux is still loading.

Signed-off-by: Leo <5faf251baee50ee6bcde338aef6acdd70bb3e60115664c2cd490d94a55dfc488@buzz.block.builderlab.xyz>
This commit is contained in:
Leo
2026-08-26 12:19:12 -04:00
parent 2c207987ae
commit 28a00e9a51
3 changed files with 64 additions and 1 deletions

View File

@@ -7,6 +7,8 @@ const ROOT_ID = "6".repeat(64);
const EDIT_ID = "9".repeat(64);
const REPLY_ID = "a".repeat(64);
const DELETION_ID = "d".repeat(64);
const AUX_DELETION_ID = "e".repeat(64);
const REACTION_ID = "b".repeat(64);
const AUTHOR = "f".repeat(64);
const CHANNEL = "chan-uuid";
@@ -52,6 +54,21 @@ function deletionEvent(id, targetId) {
};
}
function reactionEvent(id, targetId, emoji) {
return {
id,
pubkey: AUTHOR,
kind: 7,
created_at: 2500,
content: emoji,
tags: [
["h", CHANNEL],
["e", targetId],
],
sig: "s",
};
}
function head(channelEvents, replyEvents) {
return buildIndependentThreadPanel(
channelEvents,
@@ -143,3 +160,27 @@ test("applies a head deletion carried in the channel window", () => {
const result = head([root, deletion], []);
assert.equal(result, null);
});
// Deletion closure: the channel window holds an edit on the head PLUS a deletion
// of that edit (the deletion `#e`-references the EDIT id, not the head). The
// thread head must keep the original, un-edited body — the main timeline does,
// because it has the deletion. Before the closure fix the deletion was dropped
// and the panel resurrected the deleted edit.
test("does not resurrect a deleted head edit carried in the channel window", () => {
const root = contentEvent(ROOT_ID, "two PRs");
const edit = editEvent(EDIT_ID, ROOT_ID, "these PRs (3)", 2000);
const deletion = deletionEvent(AUX_DELETION_ID, EDIT_ID);
const result = head([root, edit, deletion], []);
assert.equal(result?.body, "two PRs");
assert.equal(result?.edited, false);
});
// Same closure for reactions: a deleted reaction on the head must not reappear
// in the thread panel.
test("does not resurrect a deleted head reaction carried in the channel window", () => {
const root = contentEvent(ROOT_ID, "two PRs");
const reaction = reactionEvent(REACTION_ID, ROOT_ID, "👍");
const deletion = deletionEvent(AUX_DELETION_ID, REACTION_ID);
const result = head([root, reaction, deletion], []);
assert.equal(result?.reactions, undefined);
});

View File

@@ -4,6 +4,10 @@ import {
} from "@/features/messages/lib/formatTimelineMessages";
import { buildThreadPanelData } from "@/features/messages/lib/threadPanel";
import type { RelayEvent } from "@/shared/api/types";
import {
KIND_DELETION,
KIND_NIP29_DELETE_EVENT,
} from "@/shared/constants/kinds";
/**
* Aux events (edits/deletions/reactions) already loaded in the channel window
@@ -17,17 +21,33 @@ import type { RelayEvent } from "@/shared/api/types";
*
* Restricted to non-content kinds so reply content events (which also `#e` the
* head as their parent) never leak in here — replies come from `replyEvents`.
*
* Deletion closure: an edit/reaction on the head can itself be deleted by a
* kind:5/9005 that `#e`-references the *overlay's* id, not the head's. Those
* deletions are copied too, so a deleted edit/reaction stays deleted in the
* thread head instead of being resurrected until the async aux backfill lands
* (or permanently if it fails) — mirroring the closure the aux-backfill paths
* build (`mergeAuxEventsWithDeletionBackfill`).
*/
function headAuxEventsFromChannelWindow(
channelEvents: RelayEvent[],
headId: string,
): RelayEvent[] {
return channelEvents.filter(
const directAux = channelEvents.filter(
(event) =>
event.id !== headId &&
!isTimelineContentEvent(event) &&
event.tags.some((tag) => tag[0] === "e" && tag[1] === headId),
);
const directAuxIds = new Set(directAux.map((event) => event.id));
const deletionsOfAux = channelEvents.filter(
(event) =>
(event.kind === KIND_DELETION ||
event.kind === KIND_NIP29_DELETE_EVENT) &&
!directAuxIds.has(event.id) &&
event.tags.some((tag) => tag[0] === "e" && directAuxIds.has(tag[1])),
);
return [...directAux, ...deletionsOfAux];
}
export function buildIndependentThreadPanel(

View File

@@ -1,6 +1,7 @@
import { expect, test } from "@playwright/test";
import { installMockBridge, TEST_IDENTITIES } from "../helpers/bridge";
import { waitForAnimations } from "../helpers/animations";
// Regression coverage for the reported bug: the top-level timeline shows the
// EDITED message body, but opening its thread panel shows the STALE, un-edited
@@ -131,5 +132,6 @@ test("thread head reflects the channel-window edit even before thread aux loads"
await expect(headBody).toContainText("these PRs?");
await expect(headBody).not.toContainText("these two PRs?");
await waitForAnimations(page);
await page.screenshot({ path: `${SHOT}/thread-head-edited.png` });
});