Skip to content

Commit a511ca2

Browse files
baxenmbot
andcommitted
fix(relay): show one quiet reconnect toast after 30 s, above the composer
Relay recovery now shows a single buttonless bottom-right notice, "Buzz is having trouble connecting / Retrying automatically.", on every page and only once recovery has lasted 30 s. The inline strip and its Retry now are gone; while recovery runs, the timeline edge error and the composer's agents error stay hidden. Docked composers and the preview Join notice register with useToastClearance so the toast stack rises above them instead of covering Send. Co-authored-by: mbot <3754f8729004d95654c46dbab3129e4ab9ef05cc2534e2a3fbfc155983bd637b@buzz.block.builderlab.xyz> Signed-off-by: Bradley Axen <[email protected]>
1 parent fa5bf08 commit a511ca2

25 files changed

Lines changed: 380 additions & 326 deletions

‎docs/buzz-help.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ revokes all of them, and a pairing unused for 30 days expires.
301301
- **Offline**: when Buzz can't reach a community, it shows the conversations
302302
saved on this device. Once Buzz reconnects, you can load messages older than
303303
those, and the top of the conversation says so.
304+
- **Losing the connection**: Buzz keeps retrying on its own and says nothing
305+
for the first 30 seconds. If it still can't connect, a notice at the bottom
306+
right says "Buzz is having trouble connecting" until it reconnects. There is
307+
nothing to press.
304308
- **Finding channels**: search's **Channels** tab lists the community's open
305309
channels you can join, with their member counts; typing also matches channels
306310
you're in. Opening an unjoined channel shows a preview with **Join**. Private

‎docs/design-system-adoption.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Use this map to find the shared owner before changing a product surface.
1919
| Modals | Dialog and AlertDialog | Use the [modal composition](../src/shared/design-system/DESIGN.md#modal-composition): shared title/description lockup, normalized sizes, secondary Close, and fixed footer gutter outside scrolling content. Page search, community setup, and workflow confirmations retain their dismissal and focus contracts. |
2020
| Panels and headers | Panel and PanelHeader | Settings, channels, and companion cards share appearance. Features own grids, scrolling, docks, and subscriptions. |
2121
| Read loading | LoadingRegion | Profile Settings uses a same-scope verified snapshot while refreshing; cold reads reserve the actual form geometry. Delayed status does not delay results, errors, or write feedback. |
22-
| Feedback | Toast (Sonner) | Sidebar preferences and Settings recovery use the shared bottom-right Sonner stack with source-owned recovery. Completed-action feedback can outlive its row. Channel live-update recovery stays inline above the composer; form errors, blocked pages, and lasting paused-state context stay inline. |
22+
| Feedback | Toast (Sonner) | Sidebar preferences and Settings recovery use the shared bottom-right Sonner stack with source-owned recovery. Completed-action feedback can outlive its row. Relay connection recovery is one quiet bottom-right notice on every page, and the stack rises above docked composers (`useToastClearance`), while channel live-update failures that recovery does not retry stay inline above the composer; form errors, blocked pages, and lasting paused-state context stay inline. |
2323
| Hints | Tooltip | Control hints and agent activity support keyboard access and dismissal. Controls keep their own accessible names. |
2424
| Solo chats and activity | NavigationItem, Button, IconButton, Panel, PanelHeader | Solo chat history, agent choice, and activity actions retain unread, admission, draft, and focus behavior. Base UI owns their menus. |
2525
| Media stages | `surface-inverse` and `text-inverse` | Preserve the stage’s existing values and measure text pairings. Renderers own image and video pixels. |

‎src/app/shell/PrimarySidebar.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ function ScopedSidebar({
277277
{...frame}
278278
>
279279
{/* Relay outages for every inventory recover through one
280-
automatic owner; its notice is the single Retry. */}
280+
automatic owner; its one notice shows on every page. */}
281281
{!connection.cached && (
282282
<RecoveryNotice recovery={connection.session.recovery} />
283283
)}

‎src/bundled/channels/ChannelBody.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ export const ChannelBody = memo(function ChannelBody({
9090
presented: true,
9191
});
9292
}, [cached, navigation, window.status]);
93-
// While recovery retries this timeline's head read it owns the one Retry
94-
// now, in its notice after the quiet delay; the empty timeline waits.
93+
// While recovery retries this timeline's head read, its notice is the one
94+
// report, after the quiet delay; the empty timeline waits.
9595
if (window.status === "error" && !window.rows.length && !headRecovers)
9696
return (
9797
<div

‎src/bundled/channels/LiveStatus.test.tsx‎

Lines changed: 32 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,13 @@ it.each<Partial<Snapshot>>([
9898
{ heads: [{ channelId: "a", state: "error", error: "Head read failed" }] },
9999
{ roster: { state: "error", error: "Roster refused" } },
100100
{ roster: { state: "deferred" } },
101-
])("retains recovery for degraded coverage or failures: %j", async (patch) => {
102-
expect(await render(patch, false, false, "shown")).toContain(
103-
"Reconnecting to relay…",
104-
);
105-
});
101+
])(
102+
"leaves degraded coverage or failures to the shown recovery notice: %j",
103+
async (patch) => {
104+
// The floating notice is the one report; nothing repeats it above the composer.
105+
expect(await render(patch, false, false, "shown")).toBe("");
106+
},
107+
);
106108
it.each(["channel", "global"])(
107109
"keeps bounded pending %s quota recovery in Diagnostics only",
108110
async (owner) => {
@@ -166,14 +168,13 @@ it.each<Partial<Snapshot>>([
166168
])(
167169
"does not hide actionable or unsupported failures behind automatic recovery: %j",
168170
async (patch) => {
169-
const html = await render(
170-
{ routes: [recovering], ...patch },
171-
false,
172-
false,
173-
"shown",
171+
expect(await render({ routes: [recovering], ...patch })).toContain(
172+
"Live updates limited",
174173
);
175-
expect(html).toContain("Reconnecting to relay…");
176-
expect(html).not.toContain("retry in 4s");
174+
// Once the recovery notice shows, it is the one report.
175+
expect(
176+
await render({ routes: [recovering], ...patch }, false, false, "shown"),
177+
).toBe("");
177178
},
178179
);
179180
it("a recovering global cannot hide a selected channel failure", async () => {
@@ -194,8 +195,8 @@ it("a recovering global cannot hide a selected channel failure", async () => {
194195
false,
195196
"shown",
196197
),
197-
).toContain("Reconnecting to relay…");
198-
// The notice is only a title and Retry now; Diagnostics keeps the reason.
198+
).toBe("");
199+
// The recovery notice gives no reason; Diagnostics keeps it.
199200
expect(
200201
await render(
201202
{
@@ -238,9 +239,7 @@ it.each(["pending"] as const)(
238239
it.each(["error", "deferred"] as const)(
239240
"offers roster recovery when partial discovery is %s",
240241
async (state) => {
241-
const notice = await render({ roster: { state } }, true, false, "shown");
242-
expect(notice).not.toContain("Channel list needs refreshing.");
243-
expect(notice).toContain("Reconnecting to relay…");
242+
expect(await render({ roster: { state } }, true, false, "shown")).toBe("");
244243
},
245244
);
246245
it.each<Partial<Snapshot>>([{ error: "Socket refused" }])(
@@ -252,8 +251,7 @@ it.each<Partial<Snapshot>>([{ error: "Socket refused" }])(
252251
false,
253252
"shown",
254253
);
255-
expect(notice).toContain("Reconnecting to relay…");
256-
expect(notice).not.toContain("Some channels are missing");
254+
expect(notice).toBe("");
257255
},
258256
);
259257

@@ -309,7 +307,7 @@ it("diagnostics does not duplicate notices; changing the selected channel/sessio
309307
expect(screen.queryByRole("status")).not.toBeInTheDocument();
310308
});
311309

312-
it("stays quiet before the notice delay, then shows one inline notice whose Retry now retries the session", async () => {
310+
it("stays empty while recovery runs, before and after its notice shows", async () => {
313311
const failed: Snapshot = { ...base, status: "retrying" };
314312
const quietState = Object.freeze({
315313
recovering: true,
@@ -335,48 +333,39 @@ it("stays quiet before the notice delay, then shows one inline notice whose Retr
335333
/>,
336334
);
337335
expect(screen.queryByRole("status")).not.toBeInTheDocument();
338-
const shown = recoveryIn("shown");
339336
view.rerender(
340337
<LiveStatus
341338
live={live}
342339
channelId="a"
343340
partialRoster={false}
344-
recovery={shown}
341+
recovery={recoveryIn("shown")}
345342
/>,
346343
);
347-
const notice = screen.getByRole("status", { name: "Reconnecting to relay…" });
348-
screen.getByRole("button", { name: "Retry now" }).click();
349-
expect(shown.retryNow).toHaveBeenCalledTimes(1);
350-
expect(live.retry).not.toHaveBeenCalled();
351-
// Only the title and the button: no explanatory copy.
352-
expect(notice).toHaveTextContent(/^Reconnecting to relay…Retry now$/);
344+
// The floating notice reports it; no strip or button above the composer.
345+
expect(screen.queryByRole("status")).not.toBeInTheDocument();
346+
expect(screen.queryByRole("button")).not.toBeInTheDocument();
353347
});
354348

355-
it("hands focus on when recovery removes the focused Retry now button", () => {
356-
const failed: Snapshot = { ...base, status: "retrying" };
357-
const live = {
358-
snapshot: () => failed,
359-
subscribe: () => () => {},
360-
retry: vi.fn(),
349+
it("hands focus on when the recovery notice replaces a focused Retry live updates", () => {
350+
const denied: Snapshot = {
351+
...base,
352+
status: "error",
353+
error: "Relay rejected live authentication",
361354
};
362355
const onRecovered = vi.fn();
363-
const content = (state: "idle" | "shown", view: Snapshot = failed) => (
356+
const content = (state: "idle" | "shown") => (
364357
<LiveStatus
365-
live={{ ...live, snapshot: () => view }}
358+
live={{ snapshot: () => denied, subscribe: () => () => {}, retry() {} }}
366359
channelId="a"
367360
partialRoster={false}
368361
recovery={recoveryIn(state)}
369362
onRecovered={onRecovered}
370363
/>
371364
);
372-
const view = mount(content("shown"));
373-
screen.getByRole("button", { name: "Retry now" }).focus();
374-
view.rerender(content("idle", base));
375-
expect(screen.queryByRole("button")).not.toBeInTheDocument();
376-
expect(onRecovered).toHaveBeenCalledTimes(1);
377-
// An unfocused notice leaves focus where the user put it.
365+
const view = mount(content("idle"));
366+
screen.getByRole("button", { name: "Retry live updates" }).focus();
378367
view.rerender(content("shown"));
379-
view.rerender(content("idle", base));
368+
expect(screen.queryByRole("button")).not.toBeInTheDocument();
380369
expect(onRecovered).toHaveBeenCalledTimes(1);
381370
});
382371

‎src/bundled/channels/LiveStatus.tsx‎

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ import {
66
useSyncExternalStore,
77
} from "react";
88
import type { RelaySession } from "../../features/relay/session";
9-
import {
10-
RECOVERY_TITLE,
11-
RetryNowButton,
12-
useInlineRecovery,
13-
} from "../../features/relay/RecoveryNotice";
9+
import { useRecovery } from "../../features/relay/RecoveryNotice";
1410
import { liveRecoveryStatus } from "../../features/relay/live-recovery";
1511
import { Button } from "../../shared/design-system/ui/Button";
1612
import styles from "./LiveStatus.module.css";
@@ -27,13 +23,13 @@ export function LiveStatus({
2723
channelId: string | undefined;
2824
partialRoster: boolean;
2925
diagnostics?: boolean;
30-
/** The session recovery owner. A mounted status shows its notice inline
31-
* above the composer, in place of the floating fallback. */
26+
/** The session recovery owner. While its notice shows, that notice is the
27+
* one report, so this status stays empty. */
3228
recovery?: RelaySession["recovery"];
33-
/** A recovery or retry control that had focus went away; move focus on. */
29+
/** A retry control that had focus went away; move focus on. */
3430
onRecovered?: (() => void) | undefined;
3531
}) {
36-
const { recovering: retrying, shown } = useInlineRecovery(
32+
const { recovering: retrying, shown } = useRecovery(
3733
diagnostics ? undefined : recovery,
3834
);
3935
const focused = useRef(false);
@@ -130,14 +126,8 @@ export function LiveStatus({
130126
if (keep?.reason !== held?.reason || keep?.channelId !== held?.channelId)
131127
setHeld(keep);
132128
const manual = failed || holding;
133-
const control = diagnostics
134-
? undefined
135-
: recovery && shown
136-
? "recovery"
137-
: manual
138-
? "manual"
139-
: undefined;
140-
// Either control can go away while focused, by recovery or by an automatic
129+
const control = diagnostics || shown || !manual ? undefined : "manual";
130+
// The control can go away while focused, by recovery or by an automatic
141131
// retry. A removed element does not always report blur, so check where
142132
// focus landed once the control changed.
143133
useEffect(() => {
@@ -180,21 +170,7 @@ export function LiveStatus({
180170
</>
181171
);
182172
}
183-
if (recovery && shown)
184-
return (
185-
<section
186-
role="status"
187-
aria-label={RECOVERY_TITLE}
188-
className={styles.recovery}
189-
{...track}
190-
>
191-
<div className={styles.message}>
192-
<p className="text-label-sm text-warning">{RECOVERY_TITLE}</p>
193-
</div>
194-
<RetryNowButton recovery={recovery} />
195-
</section>
196-
);
197-
if (quiet && !holding) return null;
173+
if (shown || (quiet && !holding)) return null;
198174
return (
199175
<section
200176
role="status"

‎src/features/messages/ChannelJoinNotice.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useEffect, useLayoutEffect, useRef, useState } from "react";
22
import type { ChannelLifecycleCapability } from "../relay/channel-lifecycle";
33
import { ChannelLifecycleUnconfirmed } from "../relay/channel-lifecycle";
44
import { Button } from "../../shared/design-system/ui/Button";
5+
import { useToastClearance } from "../../shared/design-system/ui/Toast";
56
import styles from "./Messages.module.css";
67

78
/** Archived and read-only channels share the public preview's lower notice.
@@ -32,6 +33,8 @@ export function ChannelJoinNotice({
3233
onHeightChange?(height: number): void;
3334
}) {
3435
const notice = useRef<HTMLElement>(null);
36+
// Notices float above Join, not over it.
37+
useToastClearance(notice);
3538
const [revealedChannel, setRevealedChannel] = useState<string>();
3639
const visible = ready || revealedChannel === channelId;
3740
useEffect(() => {

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ function setup({
135135
loadingOlder = false,
136136
historyLimited = false,
137137
error = undefined as string | undefined,
138+
recovering = false,
138139
initial = undefined as unknown,
139140
mounted = [] as { id: string; y: number }[],
140141
initialRows = undefined as ChannelMessage[] | undefined,
@@ -274,6 +275,15 @@ function setup({
274275
// Geometry fixtures are read-only; reading behavior has its own boundary tests.
275276
unread: { sync: () => ({ capability: "unsupported" }) },
276277
media: () => undefined,
278+
recovery: {
279+
snapshot: () => ({
280+
recovering,
281+
attempt: 0,
282+
shown: false,
283+
reauthorized: 0,
284+
}),
285+
subscribe: () => () => {},
286+
},
277287
} as unknown as RelaySession);
278288
let rows = initialRows ?? [timelineMessage("first"), timelineMessage("last")];
279289
type Section = ReactElement<{
@@ -415,6 +425,23 @@ function setup({
415425
}>;
416426
return edge.props.children.some((child) => child?.type === Button);
417427
},
428+
/** The edge's alert text, if any. */
429+
alert() {
430+
const edge = section.props.children[0] as ReactElement<{
431+
children: ReactElement<{ role?: string; children: unknown }>[];
432+
}>;
433+
return edge.props.children.find(
434+
(child) => child?.type === "span" && child.props.role === "alert",
435+
)?.props.children;
436+
},
437+
/** The edge's history button label, if any. */
438+
historyButton() {
439+
const edge = section.props.children[0] as ReactElement<{
440+
children: ReactElement<{ children: unknown }>[];
441+
}>;
442+
return edge.props.children.find((child) => child?.type === Button)?.props
443+
.children;
444+
},
418445
/** The edge's plain caption text, if any (not its alert or status). */
419446
caption() {
420447
const edge = section.props.children[0] as ReactElement<{
@@ -2037,6 +2064,21 @@ it.each([false, true])(
20372064
},
20382065
);
20392066

2067+
it("leaves a failed read to the recovery notice while the connection recovers", () => {
2068+
const failed = setup({ hasMore: true, error: "Read failed" });
2069+
expect(failed.alert()).toBe("Read failed");
2070+
expect(failed.historyButton()).toBe("Retry older messages");
2071+
failed.unmount();
2072+
const recovering = setup({
2073+
hasMore: true,
2074+
error: "Read failed",
2075+
recovering: true,
2076+
});
2077+
expect(recovering.alert()).toBeUndefined();
2078+
expect(recovering.historyButton()).toBe("Load older messages");
2079+
recovering.unmount();
2080+
});
2081+
20402082
it("pages Solo chat history on scroll without an initial button and keeps error recovery", () => {
20412083
const h = setup({ hasMore: true, historyControl: "scroll" });
20422084
expect(h.hasHistoryButton()).toBe(false);

‎src/features/messages/ChannelTimeline.tsx‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import type {
4545
ChannelWindow,
4646
} from "../relay/contracts";
4747
import { useRowProfiles } from "../relay/react";
48+
import { useRecovery } from "../relay/RecoveryNotice";
4849
import { geometryFor, geometrySignature } from "./geometry";
4950
import { readView, writeView } from "../../shared/view-state";
5051
import styles from "./Messages.module.css";
@@ -700,6 +701,10 @@ function Timeline({
700701
return () => observer.disconnect();
701702
}, []);
702703
useMessageSelection(scroller, rows, queries);
704+
// While the connection recovers, its notice is the one report; the history
705+
// edge does not repeat a failed read.
706+
const { recovering } = useRecovery(queries.recovery);
707+
const edgeError = recovering ? undefined : window.error;
703708
// Keep pagination space through EOF so removing its control cannot change
704709
// Virtua's start margin in the same measurement cycle as a prepend.
705710
const [reserveHistorySpace, setReserveHistorySpace] = useState(false);
@@ -1778,12 +1783,12 @@ function Timeline({
17781783
className={styles.edge}
17791784
data-history-space={reserveHistorySpace || undefined}
17801785
>
1781-
{window.error && <span role="alert">{window.error}</span>}
1786+
{edgeError && <span role="alert">{edgeError}</span>}
17821787
{window.historyLimited ? (
17831788
<span>History window limit reached</span>
17841789
) : window.hasMore && queries.channels.cachedOnly ? (
17851790
<span>You can load older messages once Buzz reconnects.</span>
1786-
) : window.hasMore && (historyControl === "button" || window.error) ? (
1791+
) : window.hasMore && (historyControl === "button" || edgeError) ? (
17871792
<Button
17881793
type="button"
17891794
disabled={window.loadingOlder}
@@ -1796,7 +1801,7 @@ function Timeline({
17961801
>
17971802
{window.loadingOlder
17981803
? "Loading older…"
1799-
: window.error
1804+
: edgeError
18001805
? "Retry older messages"
18011806
: "Load older messages"}
18021807
</Button>

0 commit comments

Comments
 (0)