Fix tape nav rerender loop

This commit is contained in:
dirtydishes 2026-05-13 11:08:14 -04:00
parent a58a3071e8
commit af04875107
3 changed files with 35 additions and 1 deletions

View file

@ -28,6 +28,7 @@ import {
mergeNewestWithOverflow,
normalizeAlertSeverity,
nextFlowFilterPopoverState,
prunePinnedEntries,
projectPausableTapeState,
reducePausableTapeData,
shouldRetainLiveSnapshotHistory,
@ -77,6 +78,20 @@ const makeAlert = (overrides: Record<string, unknown> = {}) =>
...overrides
}) as any;
describe("pinned evidence pruning", () => {
it("returns the existing map when no entries need pruning", () => {
const now = 50_000;
const current = new Map([
["flowpacket:1", { value: { id: "flowpacket:1" }, updatedAt: now - 500 }],
["trace:2", { value: { id: "trace:2" }, updatedAt: now - 1_000 }]
]);
const next = prunePinnedEntries(current, new Set(), now);
expect(next).toBe(current);
});
});
describe("live manifest", () => {
it("includes only tape channels on /tape", () => {
const filters = buildDefaultFlowFilters();

View file

@ -1894,7 +1894,7 @@ const upsertPinnedEntries = <T,>(
return next;
};
const prunePinnedEntries = <T,>(
export const prunePinnedEntries = <T,>(
current: Map<string, PinnedEntry<T>>,
activeKeys: Set<string>,
now: number
@ -1909,6 +1909,24 @@ const prunePinnedEntries = <T,>(
surviving.sort((a, b) => b[1].updatedAt - a[1].updatedAt);
const trimmed = surviving.slice(0, PINNED_EVIDENCE_MAX_ITEMS);
if (trimmed.length === current.size) {
let unchanged = true;
let index = 0;
for (const entry of current) {
const next = trimmed[index];
if (!next || next[0] !== entry[0] || next[1] !== entry[1]) {
unchanged = false;
break;
}
index += 1;
}
if (unchanged) {
return current;
}
}
return new Map(trimmed);
};