Skip to content

Commit 6abf614

Browse files
tlongwell-blocknpub1qyvc0c5kl4gqv2fd97fsk46tu378sqgy35vc83rvgfwne90sel7s0ed67dTyler Longwell
authored
fix(desktop): keep thread-summary badges mounted through scrollback prepends (#1533)
Signed-off-by: Tyler Longwell <[email protected]> Co-authored-by: npub1qyvc0c5kl4gqv2fd97fsk46tu378sqgy35vc83rvgfwne90sel7s0ed67d <011987e296fd5006292d2f930b574be47c7801048d1983c46c425d3c95f0cffd@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Tyler Longwell <[email protected]>
1 parent cfa2089 commit 6abf614

4 files changed

Lines changed: 113 additions & 2 deletions

File tree

‎desktop/src/features/channels/ui/ChannelPane.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ export const ChannelPane = React.memo(function ChannelPane({
611611
}
612612
isLoading={isTimelineLoading}
613613
mainEntries={mainTimelineEntries}
614+
threadSummaries={threadSummaries}
614615
messages={visibleMessages}
615616
firstUnreadMessageId={firstUnreadMessageId}
616617
unreadCount={unreadCount}

‎desktop/src/features/messages/ui/MessageTimeline.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import { getDmParticipantPreview } from "@/features/channels/lib/dmParticipantDisplay";
1111
import type { TimelineMessage } from "@/features/messages/types";
1212
import type { MainTimelineEntry } from "@/features/messages/lib/threadPanel";
13+
import type { ChannelWindowThreadSummary } from "@/features/messages/lib/channelWindowStore";
1314
import type { UserProfileLookup } from "@/features/profile/lib/identity";
1415
import type { ChannelType } from "@/shared/api/types";
1516
import { cn } from "@/shared/lib/cn";
@@ -37,6 +38,9 @@ type MessageTimelineProps = {
3738
huddleMemberPubkeysPending?: boolean;
3839
messages: TimelineMessage[];
3940
mainEntries?: MainTimelineEntry[];
41+
/** Relay thread summaries (root id → summary) for the deferred-pass entry
42+
* fallback, so badge rows survive while a scrollback page commits. */
43+
threadSummaries?: ReadonlyMap<string, ChannelWindowThreadSummary>;
4044
directMessageIntro?: {
4145
displayName: string;
4246
participants: DirectMessageIntroParticipant[];
@@ -143,6 +147,7 @@ const MessageTimelineBase = React.forwardRef<
143147
directMessageIntro = null,
144148
messages,
145149
mainEntries,
150+
threadSummaries,
146151
isLoading = false,
147152
emptyTitle = "No messages yet",
148153
emptyDescription = "Send the first message to start the thread.",
@@ -592,6 +597,7 @@ const MessageTimelineBase = React.forwardRef<
592597
mainEntries={
593598
deferredMessages === messages ? mainEntries : undefined
594599
}
600+
threadSummaries={threadSummaries}
595601
messages={deferredMessages}
596602
onDelete={onDelete}
597603
onEdit={onEdit}

‎desktop/src/features/messages/ui/TimelineMessageList.tsx‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import { THREAD_REPLY_ROW_MARGIN_INLINE_REM } from "@/features/messages/lib/threadTreeLayout";
1212
import { buildMainTimelineEntries } from "@/features/messages/lib/threadPanel";
1313
import type { MainTimelineEntry } from "@/features/messages/lib/threadPanel";
14+
import type { ChannelWindowThreadSummary } from "@/features/messages/lib/channelWindowStore";
1415
import {
1516
buildVideoReviewCommentsByRootId,
1617
buildVideoReviewContextForMessage,
@@ -45,6 +46,10 @@ type TimelineMessageListProps = {
4546
/** Hoisted main-timeline entries (computed once in ChannelPane). Falls back
4647
* to deriving them here when omitted (e.g. the deferred-render pass). */
4748
mainEntries?: MainTimelineEntry[];
49+
/** Relay thread summaries keyed by thread root id. Keeps badge rows alive on
50+
* the deferred-render fallback — replies usually are not local timeline
51+
* rows, so without the relay map every summary row unmounts mid-scrollback. */
52+
threadSummaries?: ReadonlyMap<string, ChannelWindowThreadSummary>;
4853
messages: TimelineMessage[];
4954
onDelete?: (message: TimelineMessage) => void;
5055
onEdit?: (message: TimelineMessage) => void;
@@ -93,6 +98,7 @@ export const TimelineMessageList = React.memo(function TimelineMessageList({
9398
isMessageUnreadById,
9499
messageFooters,
95100
mainEntries,
101+
threadSummaries,
96102
messages,
97103
onDelete,
98104
onEdit,
@@ -110,8 +116,10 @@ export const TimelineMessageList = React.memo(function TimelineMessageList({
110116
unfollowThreadById,
111117
}: TimelineMessageListProps) {
112118
const entries = React.useMemo(
113-
() => mainEntries ?? buildMainTimelineEntries(messages),
114-
[mainEntries, messages],
119+
() =>
120+
mainEntries ??
121+
buildMainTimelineEntries(messages, undefined, threadSummaries, profiles),
122+
[mainEntries, messages, profiles, threadSummaries],
115123
);
116124
const reviewCommentsByRootId = React.useMemo(
117125
() =>

‎desktop/tests/e2e/scroll-history.spec.ts‎

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,3 +1834,99 @@ test("older-history prepend keeps the reading row fixed (no jump to oldest)", as
18341834
"Jump to latest",
18351835
);
18361836
});
1837+
1838+
// Regression: thread-summary badges must not flash during a scrollback prepend.
1839+
// When an older page lands, the urgent render pass still paints the OLD
1840+
// deferred message snapshot, so MessageTimeline passes `mainEntries=undefined`
1841+
// and TimelineMessageList rebuilds entries itself. That fallback used to drop
1842+
// the relay summary map — and since thread replies are usually not local
1843+
// timeline rows, every relay-driven badge unmounted for the whole deferred
1844+
// window and remounted when the heavy render committed (the visible flash).
1845+
// A MutationObserver is commit-granular, so it catches even a single-frame
1846+
// unmount that a polling assertion would race past.
1847+
test("thread summary badge survives an older-history prepend without unmounting", async ({
1848+
page,
1849+
}, testInfo) => {
1850+
testInfo.setTimeout(60_000);
1851+
await installMockBridge(page);
1852+
await page.goto("/");
1853+
await page.waitForFunction(
1854+
() => typeof window.__BUZZ_E2E_EMIT_MOCK_MESSAGE__ === "function",
1855+
);
1856+
1857+
// Seed a reply to the NEWEST deep-history row before the channel is opened:
1858+
// no live subscription exists yet, so the reply lands only in the mock store.
1859+
// It is not a top-level timeline row, so the badge rendered for #599 is
1860+
// driven purely by the relay-shaped 39005 page summary — exactly the state
1861+
// the deferred-pass entry fallback used to drop.
1862+
await page.evaluate(() => {
1863+
window.__BUZZ_E2E_EMIT_MOCK_MESSAGE__?.({
1864+
channelName: "deep-history",
1865+
content: "summary-only reply",
1866+
parentEventId: "mock-deep-history-599",
1867+
});
1868+
});
1869+
1870+
await page.getByTestId("channel-deep-history").click();
1871+
await expect(page.getByTestId("chat-title")).toHaveText("deep-history");
1872+
const timeline = page.getByTestId("message-timeline");
1873+
const badgeSelector =
1874+
'[data-testid="message-thread-summary"][data-thread-head-id="mock-deep-history-599"]';
1875+
await expect(timeline.locator(badgeSelector)).toBeVisible();
1876+
1877+
const oldestRenderedIndex = () =>
1878+
timeline.evaluate((element) => {
1879+
let min = Number.POSITIVE_INFINITY;
1880+
for (const row of (
1881+
element as HTMLDivElement
1882+
).querySelectorAll<HTMLElement>("[data-message-id]")) {
1883+
const match = row.textContent?.match(/#(\d+)/);
1884+
if (match) min = Math.min(min, Number(match[1]));
1885+
}
1886+
return Number.isFinite(min) ? min : null;
1887+
});
1888+
const oldestBefore = await oldestRenderedIndex();
1889+
expect(oldestBefore).not.toBeNull();
1890+
1891+
// Arm the observer AFTER the initial window has settled, so the only
1892+
// mutations it sees are the prepend landing and any (buggy) badge unmount.
1893+
await timeline.evaluate((element, selector) => {
1894+
const scroller = element as HTMLDivElement;
1895+
const win = window as typeof window & {
1896+
__SUMMARY_FLASH_PROBE__?: { missingCommits: number };
1897+
};
1898+
const probe = { missingCommits: 0 };
1899+
win.__SUMMARY_FLASH_PROBE__ = probe;
1900+
new MutationObserver(() => {
1901+
if (!scroller.querySelector(selector)) {
1902+
probe.missingCommits += 1;
1903+
}
1904+
}).observe(scroller, { childList: true, subtree: true });
1905+
}, badgeSelector);
1906+
1907+
// Scroll back until a genuinely older page has landed.
1908+
await timeline.hover();
1909+
await expect
1910+
.poll(
1911+
async () => {
1912+
await page.mouse.wheel(0, -4000);
1913+
await page.waitForTimeout(50);
1914+
return oldestRenderedIndex();
1915+
},
1916+
{ timeout: 20_000 },
1917+
)
1918+
.toBeLessThan(oldestBefore ?? Number.POSITIVE_INFINITY);
1919+
1920+
// The badge row must have stayed mounted through every DOM commit of the
1921+
// prepend — zero commits observed it missing — and still be attached now.
1922+
const missingCommits = await page.evaluate(
1923+
() =>
1924+
(
1925+
window as typeof window & {
1926+
__SUMMARY_FLASH_PROBE__?: { missingCommits: number };
1927+
}
1928+
).__SUMMARY_FLASH_PROBE__?.missingCommits,
1929+
);
1930+
expect(missingCommits).toBe(0);
1931+
await expect(timeline.locator(badgeSelector)).toHaveCount(1);
1932+
});

0 commit comments

Comments
 (0)