Skip to content

Commit ae687c7

Browse files
authored
Polish message and thread spacing, grouping, and typography (#364)
Signed-off-by: Arjun Mahanti <[email protected]>
1 parent b217388 commit ae687c7

33 files changed

Lines changed: 723 additions & 215 deletions

‎patches/[email protected]‎

Lines changed: 84 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,64 @@
11
diff --git a/lib/index.js b/lib/index.js
2-
index a183cc7..a892a1c 100644
2+
index a183cc7b..44e2d963 100644
33
--- a/lib/index.js
44
+++ b/lib/index.js
5-
@@ -7,1 +7,5 @@
5+
@@ -6,6 +6,10 @@ import { jsx as c } from "react/jsx-runtime";
6+
-
7+
+
68
import { flushSync as f } from "react-dom";
9+
-
710
+
811
+// WebKit can restore a stale native scroll offset after an instant correction.
912
+// Interrupt only the corrected axis; observer-inferred idle is not native idle.
1013
+const isMacWebKit = () => typeof navigator !== "undefined" && !b() && navigator.platform === "MacIntel" && navigator.vendor === "Apple Computer, Inc.";
11-
@@ -252 +256,19 @@ var {min: a, max: u, abs: d, floor: h} = Math, g = (e, t, n) => a(n, u(t, e)), v
14+
+
15+
var {min: a, max: u, abs: d, floor: h} = Math, g = (e, t, n) => a(n, u(t, e)), v = e => [ ...e ].sort((e, t) => e - t), p = setTimeout, S = clearTimeout, m = "function" == typeof queueMicrotask ? queueMicrotask : e => {
16+
Promise.resolve().then(e);
17+
}, $ = () => {
18+
@@ -173,15 +177,37 @@ var {min: a, max: u, abs: d, floor: h} = Math, g = (e, t, n) => a(n, u(t, e)), v
19+
q: () => [ l.slice(), o ]
20+
};
21+
}, C = e => {
22+
- let t;
23+
+ let t, view, frame;
24+
+ const observed = new Set, pending = new Map;
25+
return {
26+
A(n) {
27+
- (t || (t = new (z(_(n)).ResizeObserver)(e))).observe(n);
28+
+ observed.add(n);
29+
+ if (!t) {
30+
+ view = z(_(n));
31+
+ // Rendering from native resize delivery can mount same-depth
32+
+ // items and trigger WebKit's skipped-notification loop.
33+
+ t = new view.ResizeObserver(entries => {
34+
+ for (const entry of entries) if (observed.has(entry.target)) pending.set(entry.target, entry);
35+
+ if (pending.size && frame === undefined) frame = view.requestAnimationFrame(() => {
36+
+ frame = undefined;
37+
+ const batch = [...pending.values()];
38+
+ pending.clear();
39+
+ if (batch.length) e(batch);
40+
+ });
41+
+ });
42+
+ }
43+
+ t.observe(n);
44+
},
45+
B(e) {
46+
+ observed.delete(e);
47+
+ pending.delete(e);
48+
t.unobserve(e);
49+
},
50+
X() {
51+
+ if (frame !== undefined) view.cancelAnimationFrame(frame);
52+
+ frame = undefined;
53+
+ pending.clear();
54+
+ observed.clear();
55+
t && t.disconnect();
56+
}
57+
};
58+
@@ -249,10 +275,28 @@ var {min: a, max: u, abs: d, floor: h} = Math, g = (e, t, n) => a(n, u(t, e)), v
59+
o && o();
60+
} ];
61+
}, E = (e, t) => {
1262
- let n, o, r = $(), i = !1;
1363
+ let n, o, r = $(), i = !1, restoreOverflow;
1464
+ // Scroll APIs can truncate fractional offsets. Reach the whole edge without
@@ -29,20 +79,46 @@ index a183cc7..a892a1c 100644
2979
+ }, timer = p(restore);
3080
+ restoreOverflow = restore;
3181
+ };
32-
@@ -255 +277 @@ var {min: a, max: u, abs: d, floor: h} = Math, g = (e, t, n) => a(n, u(t, e)), v
82+
const s = t ? "scrollLeft" : "scrollTop", l = t ? "left" : "top", c = t ? "overflowX" : "overflowY", [f, a] = O(e, () => r[0], (e, t) => {
83+
n.scrollTo({
3384
- [l]: T(e, i),
3485
+ [l]: T(edgeOffset(e), i),
35-
@@ -269 +291,2 @@ var {min: a, max: u, abs: d, floor: h} = Math, g = (e, t, n) => a(n, u(t, e)), v
86+
behavior: t ? "smooth" : "instant"
87+
});
88+
}), u = t ? "width" : "height", d = /* @__PURE__ */ new WeakMap, h = C(t => {
89+
@@ -266,7 +310,8 @@ var {min: a, max: u, abs: d, floor: h} = Math, g = (e, t, n) => a(n, u(t, e)), v
90+
return {
91+
D(f, u = f.parentElement) {
92+
h.A(n = u), t && (i = "rtl" === getComputedStyle(u).direction), o = M(e, u, t, () => T(u[s], i), (t, n, o) => {
3693
- if (o) {
3794
+ if (isMacWebKit()) interruptMomentum();
3895
+ else if (o) {
39-
@@ -277 +300 @@ var {min: a, max: u, abs: d, floor: h} = Math, g = (e, t, n) => a(n, u(t, e)), v
96+
const e = u.style, t = e[c];
97+
e[c] = "hidden", p(() => {
98+
e[c] = t;
99+
@@ -274,7 +319,7 @@ var {min: a, max: u, abs: d, floor: h} = Math, g = (e, t, n) => a(n, u(t, e)), v
100+
}
101+
const r = e.T() + t;
102+
r <= 0 || r >= e.O() + e.t() - e.o() ? u.scrollTo({
40103
- [l]: T(r, i),
41104
+ [l]: T(edgeOffset(r), i),
42-
@@ -286 +309 @@ var {min: a, max: u, abs: d, floor: h} = Math, g = (e, t, n) => a(n, u(t, e)), v
105+
behavior: "instant"
106+
}) : u.scrollBy({
107+
[l]: T(t, i),
108+
@@ -283,7 +328,7 @@ var {min: a, max: u, abs: d, floor: h} = Math, g = (e, t, n) => a(n, u(t, e)), v
109+
}), r[1](!0);
110+
},
111+
_() {
43112
- h.X(), o && o.X(), r[1](!1), r = $();
44113
+ restoreOverflow && restoreOverflow(), h.X(), o && o.X(), r[1](!1), r = $();
45-
@@ -799,2 +822 @@ var {min: a, max: u, abs: d, floor: h} = Math, g = (e, t, n) => a(n, u(t, e)), v
114+
},
115+
P: (e, t) => (d.set(e, t), h.A(e), () => {
116+
d.delete(e), h.B(e);
117+
@@ -796,5 +841,4 @@ var {min: a, max: u, abs: d, floor: h} = Math, g = (e, t, n) => a(n, u(t, e)), v
118+
});
119+
});
120+
-
121+
+
46122
-export { G as VList, j as Virtualizer, U as WindowVirtualizer, N as experimental_VGrid };
47123
-//# sourceMappingURL=index.js.map
48124
\ No newline at end of file

‎pnpm-lock.yaml‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/features/messages/ChannelTimeline.report.test.tsx‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,7 @@ async function openReport(row: HTMLElement) {
146146
name: "More message actions",
147147
});
148148
await user.click(trigger);
149-
await user.click(
150-
await screen.findByRole("menuitem", { name: "Report message" }),
151-
);
149+
await user.click(await screen.findByRole("menuitem", { name: "Report" }));
152150
await screen.findByRole("dialog", { name: "Report message" });
153151
return { user, trigger };
154152
}

‎src/features/messages/ChannelTimeline.test.tsx‎

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,10 @@ it("restores an anchor inside a membership group after history joins across a pa
11461146
membershipRow("anchor", 2),
11471147
membershipRow("newer", 3),
11481148
]);
1149-
expect(h.handle.scrollToIndex).not.toHaveBeenCalled();
1149+
expect(h.handle.scrollToIndex).toHaveBeenCalledExactlyOnceWith(0, {
1150+
align: "start",
1151+
offset: -42,
1152+
});
11501153
h.unmount();
11511154
});
11521155
it("live group growth follows the displayed group index rather than a hidden raw row", () => {
@@ -1464,3 +1467,48 @@ it("estimated list shrinkage can leave an intermediate gap without becoming read
14641467
h.unmount();
14651468
expect(h.saved().bottom).toBe(true);
14661469
});
1470+
1471+
it("records a measured shrink before an append hides its queued native scroll clamp", () => {
1472+
const h = setup();
1473+
h.element.scrollTop = 3038;
1474+
h.scroll();
1475+
h.append();
1476+
h.element.scrollHeight -= 200;
1477+
h.element.scrollTop -= 200;
1478+
h.measureRows(false); // Mutation delivery precedes the queued native scroll.
1479+
h.element.scrollHeight += 300; // A new event arrives before that scroll.
1480+
h.dispatchScroll();
1481+
h.handle.scrollToIndex.mockClear();
1482+
h.flush();
1483+
expect(h.handle.scrollToIndex).toHaveBeenCalledExactlyOnceWith(2, {
1484+
align: "end",
1485+
});
1486+
h.unmount();
1487+
expect(h.saved().bottom).toBe(true);
1488+
});
1489+
1490+
it.each([false, true])(
1491+
"a row refresh before the first measured height preserves cold restoration unless the reader intervenes=%s",
1492+
(gesture) => {
1493+
const mountedRow = { id: "last", y: 42 };
1494+
const mounted = [mountedRow];
1495+
const h = setup({
1496+
initial: { offset: 80851, bottom: false, anchor: { id: "last", y: 42 } },
1497+
mounted,
1498+
});
1499+
mountedRow.y = 142; // Native cold layout can report the right ID at the wrong Y.
1500+
h.dispatchScroll();
1501+
if (gesture) h.gesture();
1502+
h.handle.scrollToIndex.mockClear();
1503+
h.edit(); // Refresh cancels the original observer before any height delivery.
1504+
h.handle.scrollToIndex.mockClear();
1505+
h.measureRows();
1506+
if (gesture) expect(h.handle.scrollToIndex).not.toHaveBeenCalled();
1507+
else
1508+
expect(h.handle.scrollToIndex).toHaveBeenCalledExactlyOnceWith(1, {
1509+
align: "start",
1510+
offset: -42,
1511+
});
1512+
h.unmount();
1513+
},
1514+
);

‎src/features/messages/ChannelTimeline.tsx‎

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { RelaySession } from "../relay/session";
88
import { useCallback, useLayoutEffect, useMemo, useRef, useState } from "react";
99
import { Virtualizer, type VirtualizerHandle } from "virtua";
1010
import { MessageRow } from "./MessageRow";
11+
import { continuesMessageGroup } from "./message-grouping";
1112
import type { Attachment, ChannelWindow } from "../relay/contracts";
1213
import { useRowProfiles } from "../relay/react";
1314
import { geometryFor, geometrySignature } from "./geometry";
@@ -302,9 +303,7 @@ function Timeline({
302303
? savedPosition.current
303304
: null;
304305
let observer: MutationObserver | undefined;
305-
let correctionPending = false;
306306
const restorePosition = () => {
307-
correctionPending = false;
308307
if (intent.current !== scheduledIntent || !handle.current) return;
309308
if (restore) {
310309
const anchor = restore.anchor;
@@ -349,8 +348,16 @@ function Timeline({
349348
observer = new MutationObserver(() => {
350349
if (list.style.height === height) return;
351350
height = list.style.height;
351+
// Capture a native clamp while its shrink is still observable.
352+
// Another append can grow the list before the queued scroll event.
353+
if (
354+
!restore &&
355+
measuredPosition.current &&
356+
intent.current === scheduledIntent &&
357+
scroller.current
358+
)
359+
recordPosition(scroller.current);
352360
cancelAnimationFrame(frame);
353-
correctionPending = true;
354361
frame = requestAnimationFrame(restorePosition);
355362
});
356363
observer.observe(list, {
@@ -364,15 +371,17 @@ function Timeline({
364371
return () => {
365372
cancelAnimationFrame(frame);
366373
observer?.disconnect();
367-
// A row refresh can cancel the late measurement correction. Carry the
368-
// original restoration across it; only newer reader input may retire it.
369-
if (
370-
correctionPending &&
371-
restore &&
372-
!follow.current &&
373-
intent.current === scheduledIntent
374-
) {
375-
savedPosition.current = restore;
374+
// A row refresh can arrive before the first deferred measurement or
375+
// cancel its correction. Keep restoration until newer reader input.
376+
if (restore && !follow.current && intent.current === scheduledIntent) {
377+
// Carry the original geometry with the resolved membership identity.
378+
savedPosition.current =
379+
restore.anchor && restoredAnchor.current
380+
? {
381+
...restore,
382+
anchor: { ...restore.anchor, id: restoredAnchor.current },
383+
}
384+
: restore;
376385
settled.current = false;
377386
}
378387
};
@@ -525,8 +534,7 @@ function Timeline({
525534
{rows.map((row, index) => {
526535
const day =
527536
index === 0
528-
? queries.channels.get?.(channelId)?.channelType !== "dm" ||
529-
window.hasMore
537+
? true
530538
: new Date(
531539
(rows[index - 1]?.createdAt ?? 0) * 1000,
532540
).toDateString() !==
@@ -545,6 +553,11 @@ function Timeline({
545553
/>
546554
) : (
547555
<MessageRow
556+
layout={
557+
continuesMessageGroup(rows[index - 1], row)
558+
? "continuation"
559+
: "timeline"
560+
}
548561
session={queries}
549562
scope={scope}
550563
key={row.id}

‎src/features/messages/MediaReviewViewer.tsx‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ function ReviewComments({
568568
</strong>
569569
<span>{replies.length}</span>
570570
</div>
571-
{replies.map((row) => (
571+
{replies.map((row, index) => (
572572
<div
573573
key={row.id}
574574
data-review-comment={row.id}
@@ -584,7 +584,12 @@ function ReviewComments({
584584
agentPubkeys={agentPubkeys}
585585
media={session.media}
586586
onOpenLink={() => false}
587-
day={false}
587+
day={
588+
index === 0 ||
589+
new Date(
590+
(replies[index - 1]?.createdAt ?? 0) * 1000,
591+
).toDateString() !== new Date(row.createdAt * 1000).toDateString()
592+
}
588593
retry={session.messages.retry}
589594
onOpenMediaReview={(_rowId, attachment, seconds) =>
590595
selectAttachment(attachment, seconds)

‎src/features/messages/MembershipRow.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const MembershipRow = memo(function MembershipRow({
4040
<div className={styles.day}>
4141
<span>
4242
{new Date(row.createdAt * 1000).toLocaleDateString(undefined, {
43+
year: "numeric",
4344
weekday: "long",
4445
month: "long",
4546
day: "numeric",

‎src/features/messages/MessageActionBar.tsx‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export function MessageActionBar({
9999
}}
100100
/>
101101
)}
102-
<span className={styles.copyLinkShortcut}>
102+
<span>
103103
<IconButton
104104
aria-label="Copy link"
105105
title={link ? "Copy link" : "Message link unavailable"}
@@ -158,17 +158,6 @@ export function MessageActionBar({
158158
</MenuIcon>
159159
Copy message
160160
</MenuItem>
161-
<MenuItem
162-
disabled={!link || copying}
163-
onClick={() => {
164-
if (link) void copy(() => link, "Link");
165-
}}
166-
>
167-
<MenuIcon>
168-
<LinkIcon />
169-
</MenuIcon>
170-
Copy link
171-
</MenuItem>
172161
{overflowItems}
173162
</AfterMenuClose.Provider>
174163
</MenuPopup>

0 commit comments

Comments
 (0)