Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(community): stop the reload avatar-flash on the window's first message

Melly0a5c9136843d
diff --git a/src/web/src/components/community/message-list-items.test.ts b/src/web/src/components/community/message-list-items.test.ts
index ac7d30d95..8d9436616 100644
--- a/src/web/src/components/community/message-list-items.test.ts
+++ b/src/web/src/components/community/message-list-items.test.ts
@@ -142,6 +142,45 @@ describe("flattenMessageItems", () => {
expect(messageItems[1].m.grouped).toBe(false)
})
+ it("forces the window-first chat message to grouped when an older page is still pending (hasMoreOlder) — avoids the reload avatar-flash", () => {
+ // Reverse-infinite window with older content beyond the top: the first
+ // message's true predecessor isn't loaded yet, so default it to grouped
+ // (no avatar) rather than guess ungrouped and pop-out on prepend.
+ const items = flattenMessageItems(
+ [
+ msg({ id: "m1", authorName: "Alice", createdAt: "2026-01-01T10:00:00.000Z" }),
+ msg({ id: "m2", authorName: "Bob", createdAt: "2026-01-01T10:01:00.000Z" }),
+ ],
+ undefined,
+ true,
+ )
+ const messageItems = items.filter((i) => i.kind === "message")
+ // First message forced grouped despite having no prev (older page pending).
+ expect(messageItems[0].m.grouped).toBe(true)
+ // A genuinely different author below still groups by the real rule.
+ expect(messageItems[1].m.grouped).toBe(false)
+ })
+
+ it("keeps the window-first message ungrouped when the top is truly reached (hasMoreOlder false) — its avatar shows correctly", () => {
+ const items = flattenMessageItems(
+ [msg({ id: "m1", authorName: "Alice", createdAt: "2026-01-01T10:00:00.000Z" })],
+ undefined,
+ false,
+ )
+ const messageItems = items.filter((i) => i.kind === "message")
+ expect(messageItems[0].m.grouped).toBe(false)
+ })
+
+ it("does not force-group a window-first SYSTEM message even with an older page pending", () => {
+ const items = flattenMessageItems(
+ [msg({ id: "m1", type: "system", systemKind: "thread" })],
+ undefined,
+ true,
+ )
+ const messageItems = items.filter((i) => i.kind === "message")
+ expect(messageItems[0].m.grouped).toBe(false)
+ })
+
it("does not group a system message even from the same author within the window", () => {
const items = flattenMessageItems(
[
diff --git a/src/web/src/components/community/message-list-items.ts b/src/web/src/components/community/message-list-items.ts
index 36f97b09b..ca03a47b0 100644
--- a/src/web/src/components/community/message-list-items.ts
+++ b/src/web/src/components/community/message-list-items.ts
@@ -27,9 +27,27 @@ export type FlatItem =
// direct unit testing (see message-list.test.ts) — mirrors `member-list.tsx`'s
// `flattenGroups`/`computeDuplicateNames` pattern of exporting pure list-prep
// logic out of the component for testability without rendering.
-export function flattenMessageItems(messages: Msg[], newDividerBefore: string | undefined): FlatItem[] {
+// `hasMoreOlder` — whether an older page exists beyond this window's top (the
+// reverse-infinite top sentinel is live). When true, the window's FIRST message
+// has an unknowable true predecessor: its real grouping can't be computed until
+// the older page loads. Defaulting it to ungrouped (avatar shown) then
+// re-grouping on prepend produces a pop-OUT flash (avatar appears, then
+// vanishes when the older same-author message arrives) — read by the eye as
+// "something broke". Instead, default the window-first message to GROUPED (no
+// avatar) while older content is still pending: the common mid-history reload
+// has that top message continuing an older same-author run (so grouped is
+// usually already correct), and when it is genuinely a new group the avatar
+// fades IN on prepend — a gentler, expected "content arrived" motion. Once the
+// top is truly reached (`hasMoreOlder` false), the first message groups by the
+// real rule (nothing above it → ungrouped → its avatar shows, correctly).
+export function flattenMessageItems(
+ messages: Msg[],
+ newDividerBefore: string | undefined,
+ hasMoreOlder = false,
+): FlatItem[] {
const items: FlatItem[] = []
let prev: Msg | null = null
+ let seenFirstMessage = false
for (const m of messages) {
const prevDate = prev ? dateKey(prev.createdAt) : ""
const curDate = dateKey(m.createdAt)
@@ -56,9 +74,15 @@ export function flattenMessageItems(messages: Msg[], newDividerBefore: string |
items.push({ kind: "new-divider", key: "new-divider" })
}
}
- const grouped = !!(prev && m.type === "chat" && !m.replyTo && !showDateDivider && prev.authorName === m.authorName
+ // Window-first message with an older page still pending: force grouped
+ // (suppress its avatar) rather than guess ungrouped — see the doc comment
+ // above. `m.type === "chat"` keeps a system message (which never groups)
+ // out of this special-case. Chat first-messages only.
+ const isPendingWindowFirst = !seenFirstMessage && hasMoreOlder && m.type === "chat"
+ const grouped = isPendingWindowFirst || !!(prev && m.type === "chat" && !m.replyTo && !showDateDivider && prev.authorName === m.authorName
&& prev.createdAt && m.createdAt && (new Date(m.createdAt).getTime() - new Date(prev.createdAt).getTime()) < MESSAGE_GROUP_WINDOW_MS)
items.push({ kind: "message", m: { ...m, grouped }, key: `msg:${m.id}` })
+ seenFirstMessage = true
prev = m
}
return items
diff --git a/src/web/src/components/community/message-list.tsx b/src/web/src/components/community/message-list.tsx
index 0267cb722..8c22e3930 100644
--- a/src/web/src/components/community/message-list.tsx
+++ b/src/web/src/components/community/message-list.tsx
@@ -101,7 +101,7 @@ export function MessageList({
// Memoized so a re-render triggered by unrelated state (typing indicator
// ticks, presence updates, etc.) doesn't re-walk the full message list
// every time.
- const items = useMemo(() => flattenMessageItems(messages, newDividerBefore), [messages, newDividerBefore])
+ const items = useMemo(() => flattenMessageItems(messages, newDividerBefore, !!hasMore), [messages, newDividerBefore, hasMore])
// The hero ("Beginning of the channel…" copy, or a caller-supplied
// `hero` node such as the thread-opener) renders OUTSIDE the virtualized