@remit/web-client 0.0.13 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remit/web-client",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "type": "module",
5
5
  "description": "Remit web client, published as composable primitives — the app shell, auth shells, and runtime config. A distributor imports what it composes and bundles it.",
6
6
  "exports": {
@@ -1,4 +1,5 @@
1
1
  import { createAuthClient } from "better-auth/react";
2
+ import { taggedFetch } from "../lib/network-error";
2
3
  import { getRuntimeConfig } from "../runtime-config";
3
4
 
4
5
  /**
@@ -51,7 +52,9 @@ const decodeExp = (token: string): number => {
51
52
  };
52
53
 
53
54
  const requestToken = async (): Promise<string | null> => {
54
- const res = await fetch("/api/auth/token", { credentials: "include" });
55
+ const res = await taggedFetch("/api/auth/token", {
56
+ credentials: "include",
57
+ });
55
58
  if (!res.ok) return null;
56
59
  const body: unknown = await res.json();
57
60
  if (
@@ -419,6 +419,7 @@ export const ComposeForm = ({
419
419
  pushError({
420
420
  title: "Couldn't save draft",
421
421
  detail: formatErrorDetail(saveError) ?? "Saving the draft failed.",
422
+ error: saveError,
422
423
  });
423
424
  }, [saveError, pushError]);
424
425
 
@@ -541,6 +542,7 @@ export const ComposeForm = ({
541
542
  pushError({
542
543
  title: "Couldn't send message",
543
544
  detail: formatErrorDetail(error) ?? "Saving the draft failed.",
545
+ error,
544
546
  });
545
547
  return null;
546
548
  });
@@ -562,6 +564,7 @@ export const ComposeForm = ({
562
564
  (createdThisAttempt
563
565
  ? "The draft was saved but the send request failed. Try again from the Outbox."
564
566
  : "The send request failed. Try again."),
567
+ error,
565
568
  });
566
569
  return null;
567
570
  });
@@ -313,15 +313,17 @@ function WiredPanel({
313
313
  [updateFlags],
314
314
  );
315
315
 
316
- // Per-sender flag toggles are always wired. They stay active even before the
317
- // address record resolves: `updateFlags` surfaces feedback when `addressId`
318
- // is missing rather than letting the button look active but do nothing.
316
+ // Every per-sender flag toggle PATCHes the sender's address row, so none of
317
+ // them can be serviced until that row resolves. Leave them unwired until it
318
+ // does: the panel renders an unwired quick action as disabled, so the flow is
319
+ // never reachable in a state where a click can only fail (issue #51).
320
+ const canUpdateFlags = addressId !== undefined;
319
321
  const actions: IntelligenceQuickActions = {
320
- onToggleVip: handleToggleVip,
321
- onToggleMute: handleToggleMute,
322
- onToggleBlock: handleToggleBlock,
323
- onToggleUnsubscribe: handleToggleUnsubscribe,
324
- onReclassify: () => setReclassifyOpen(true),
322
+ onToggleVip: canUpdateFlags ? handleToggleVip : undefined,
323
+ onToggleMute: canUpdateFlags ? handleToggleMute : undefined,
324
+ onToggleBlock: canUpdateFlags ? handleToggleBlock : undefined,
325
+ onToggleUnsubscribe: canUpdateFlags ? handleToggleUnsubscribe : undefined,
326
+ onReclassify: canUpdateFlags ? () => setReclassifyOpen(true) : undefined,
325
327
  onNotSpam: spamAction === "notSpam" ? handleNotSpam : undefined,
326
328
  onMarkSpam: spamAction === "markSpam" ? handleMarkSpam : undefined,
327
329
  };
@@ -27,6 +27,7 @@ import { formatErrorDetail } from "@/components/ui/error-banners";
27
27
  import { useDeleteMessages } from "@/hooks/useDeleteMessages";
28
28
  import { useMoveMessages } from "@/hooks/useMoveMessages";
29
29
  import { useToggleTrusted } from "@/hooks/useToggleTrusted";
30
+ import { patchThreadListCache, type ThreadListCache } from "@/lib/thread-cache";
30
31
  import { MoveToTrigger } from "./MoveToTrigger";
31
32
 
32
33
  interface ThreadMessagesData {
@@ -34,15 +35,12 @@ interface ThreadMessagesData {
34
35
  [key: string]: unknown;
35
36
  }
36
37
 
37
- interface ThreadsListPage {
38
- items: RemitImapThreadMessageResponse[];
39
- [key: string]: unknown;
40
- }
41
-
42
- interface ThreadsListData {
43
- pages: ThreadsListPage[];
44
- pageParams: Array<string | undefined>;
45
- }
38
+ /**
39
+ * Either shape a thread list/search query caches — the infinite mailbox list
40
+ * or a single-shot page. `setQueriesData` matches by key prefix, so the
41
+ * optimistic updater sees both.
42
+ */
43
+ type ThreadsListData = ThreadListCache;
46
44
 
47
45
  interface SnapshotEntry<T> {
48
46
  queryKey: readonly unknown[];
@@ -169,26 +167,20 @@ export const MessageActionMenu = ({
169
167
  },
170
168
  );
171
169
 
172
- const patchListData = (old: ThreadsListData | undefined) => {
173
- if (!old) return old;
174
- return {
175
- ...old,
176
- pages: old.pages.map((page) => ({
177
- ...page,
178
- items: page.items.map((item) =>
179
- targetIds.has(item.messageId)
180
- ? { ...item, isRead: isReadNext }
181
- : item,
182
- ),
183
- })),
184
- };
185
- };
170
+ const patchListData = (old: unknown) =>
171
+ patchThreadListCache(old, (items) =>
172
+ items.map((item) =>
173
+ targetIds.has(item.messageId)
174
+ ? { ...item, isRead: isReadNext }
175
+ : item,
176
+ ),
177
+ );
186
178
 
187
- queryClient.setQueriesData<ThreadsListData>(
179
+ queryClient.setQueriesData(
188
180
  { queryKey: threadsListPrefix },
189
181
  patchListData,
190
182
  );
191
- queryClient.setQueriesData<ThreadsListData>(
183
+ queryClient.setQueriesData(
192
184
  { queryKey: threadsSearchPrefix },
193
185
  patchListData,
194
186
  );
@@ -214,6 +206,7 @@ export const MessageActionMenu = ({
214
206
  pushError({
215
207
  title: isReadNext ? "Couldn't mark as read" : "Couldn't mark as unread",
216
208
  detail: formatErrorDetail(err),
209
+ error: err,
217
210
  });
218
211
  },
219
212
  onSettled: (_data, _err, _vars, context) => {
@@ -74,6 +74,7 @@ export const MessageDetail = ({ messageId }: MessageDetailProps) => {
74
74
  pushError({
75
75
  title: "Couldn't mark message as read",
76
76
  detail: formatErrorDetail(error),
77
+ error,
77
78
  });
78
79
  },
79
80
  });
@@ -15,12 +15,12 @@ const SEVERITY_STYLES: Record<
15
15
  { container: string; icon: string; title: string }
16
16
  > = {
17
17
  error: {
18
- container: "border-danger/50 bg-danger/10 dark:bg-danger/20",
18
+ container: "border-danger/50 bg-danger-soft",
19
19
  icon: "text-danger",
20
20
  title: "text-danger",
21
21
  },
22
22
  warning: {
23
- container: "border-warning/50 bg-warning/10",
23
+ container: "border-warning/50 bg-warning-soft",
24
24
  icon: "text-warning",
25
25
  title: "text-warning",
26
26
  },
@@ -61,7 +61,10 @@ export const ErrorBanner = ({
61
61
  role={severity === "error" ? "alert" : "status"}
62
62
  aria-live={severity === "error" ? "assertive" : "polite"}
63
63
  className={cn(
64
- "pointer-events-auto flex items-start gap-3 rounded-md border bg-canvas/80 px-3 py-2 shadow-md backdrop-blur",
64
+ // Opaque, not translucent: a banner overlaps the toolbar and the
65
+ // message list, and see-through text on top of see-through text is
66
+ // unreadable (issue #55).
67
+ "pointer-events-auto flex items-start gap-3 rounded-md border bg-canvas px-3 py-2 shadow-lg",
65
68
  styles.container,
66
69
  )}
67
70
  >
@@ -0,0 +1,85 @@
1
+ import assert from "node:assert/strict";
2
+ import { afterEach, describe, it } from "node:test";
3
+ import { createElement } from "react";
4
+ import { renderToString } from "react-dom/server";
5
+ import { ApiError } from "@/lib/api";
6
+ import { __resetFatalError, getCurrentFatalError } from "@/lib/fatal-error";
7
+ import { ErrorBannerProvider, useErrorBanners } from "./ErrorBannerProvider";
8
+ import type { PushErrorInput } from "./error-banners";
9
+
10
+ /**
11
+ * Push one error through the real provider and report where it went. The
12
+ * routing decision happens inside `pushError`, so a single render is enough:
13
+ * either a fatal was recorded, or the error stayed a soft banner.
14
+ */
15
+ const push = (input: PushErrorInput): { escalated: boolean } => {
16
+ const Pusher = () => {
17
+ useErrorBanners().pushError(input);
18
+ return null;
19
+ };
20
+ renderToString(
21
+ createElement(ErrorBannerProvider, null, createElement(Pusher)) as never,
22
+ );
23
+ return { escalated: getCurrentFatalError() !== null };
24
+ };
25
+
26
+ afterEach(() => {
27
+ __resetFatalError();
28
+ });
29
+
30
+ describe("pushError — a banner is a soft surface only", () => {
31
+ it("keeps a soft failure with no error attached in a banner", () => {
32
+ assert.equal(push({ title: "Couldn't save draft" }).escalated, false);
33
+ });
34
+
35
+ it("treats an absent error as absent, not as a bug", () => {
36
+ // A caller forwarding an optional error it does not have passes
37
+ // `undefined`. That is "nothing went wrong that we can classify", not a
38
+ // client-side exception, and must not take over the screen.
39
+ assert.equal(
40
+ push({ title: "Couldn't save draft", error: undefined }).escalated,
41
+ false,
42
+ );
43
+ assert.equal(
44
+ push({ title: "Couldn't save draft", error: null }).escalated,
45
+ false,
46
+ );
47
+ });
48
+
49
+ it("keeps a 4xx the call site owns in a banner", () => {
50
+ assert.equal(
51
+ push({
52
+ title: "Couldn't move this message",
53
+ error: new ApiError("Not found", 404),
54
+ }).escalated,
55
+ false,
56
+ );
57
+ });
58
+
59
+ it("escalates a 5xx to the fatal page instead of a toast", () => {
60
+ assert.equal(
61
+ push({
62
+ title: "Couldn't move 339 messages",
63
+ error: new ApiError("Internal error", 500),
64
+ }).escalated,
65
+ true,
66
+ );
67
+ assert.equal(getCurrentFatalError()?.message, "Internal error");
68
+ });
69
+
70
+ it("escalates an exception thrown by our own code (issue #55)", () => {
71
+ const bug = new TypeError(
72
+ 'can\'t access property "map", N.pages is undefined',
73
+ );
74
+ assert.equal(
75
+ push({ title: "Couldn't move 339 messages", error: bug }).escalated,
76
+ true,
77
+ );
78
+ assert.equal(getCurrentFatalError()?.message, bug.message);
79
+ assert.equal(
80
+ getCurrentFatalError()?.recoverable,
81
+ false,
82
+ "a bug is not something the user can retry away",
83
+ );
84
+ });
85
+ });
@@ -6,6 +6,8 @@ import {
6
6
  useMemo,
7
7
  useState,
8
8
  } from "react";
9
+ import { isAlwaysFatal } from "@/lib/error-classifier";
10
+ import { reportFatalError } from "@/lib/fatal-error";
9
11
  import { ErrorBannerStack } from "./ErrorBannerStack.js";
10
12
  import {
11
13
  appendBanner,
@@ -39,7 +41,23 @@ const generateId = (): string => {
39
41
  export const ErrorBannerProvider = ({ children }: { children: ReactNode }) => {
40
42
  const [errors, setErrors] = useState<ErrorBannerEntry[]>([]);
41
43
 
44
+ /**
45
+ * Show a soft, dismissible banner — and only that. A fatal error is not a
46
+ * notification: when the caller hands us a 5xx or an exception from our own
47
+ * code, it goes to the fatal seam instead, so the user gets the full-screen
48
+ * page with a way forward and a bug report rather than a toast they can only
49
+ * dismiss (issue #55). Those two classes are fatal with no opt-out; anything
50
+ * a call site can legitimately own — a 404 empty state, a 4xx the user can
51
+ * act on — still banners here.
52
+ *
53
+ * The guard is on the error being present, not on the key being present:
54
+ * `error` is optional, so a caller forwarding one it does not have passes
55
+ * `undefined`, and "no error at all" must not be classified as a bug.
56
+ */
42
57
  const pushError = useCallback((input: PushErrorInput): string => {
58
+ if (input.error != null && isAlwaysFatal(input.error)) {
59
+ return reportFatalError(input.error).correlationId;
60
+ }
43
61
  const entry = buildEntry(input, generateId(), Date.now());
44
62
  setErrors((current) => appendBanner(current, entry));
45
63
  return entry.id;
@@ -12,6 +12,14 @@ export interface PushErrorInput {
12
12
  severity?: ErrorBannerSeverity;
13
13
  title: string;
14
14
  detail?: string;
15
+ /**
16
+ * The error being reported, when there is one. Pass it: a banner is a soft
17
+ * surface, and `pushError` uses this to refuse errors that are not soft —
18
+ * a 5xx or a client-side exception is escalated to the full-screen fatal
19
+ * page (which offers Retry, a way out, and a bug report) instead of being
20
+ * reduced to a dismissible toast.
21
+ */
22
+ error?: unknown;
15
23
  }
16
24
 
17
25
  const MAX_BANNERS = 5;
@@ -30,6 +38,7 @@ export const buildMutationErrorBanner = (
30
38
  ): PushErrorInput => ({
31
39
  title,
32
40
  detail: formatErrorDetail(error) ?? fallback,
41
+ error,
33
42
  });
34
43
 
35
44
  export const formatErrorDetail = (error: unknown): string | undefined => {
@@ -10,6 +10,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
10
10
  import { useCallback } from "react";
11
11
  import { useErrorBanners } from "@/components/ui/ErrorBannerProvider";
12
12
  import { formatErrorDetail } from "@/components/ui/error-banners";
13
+ import { patchThreadListCache, type ThreadListCache } from "@/lib/thread-cache";
13
14
 
14
15
  interface UseDeleteMessagesOptions {
15
16
  mailboxId: string;
@@ -28,15 +29,12 @@ interface ThreadMessagesData {
28
29
  [key: string]: unknown;
29
30
  }
30
31
 
31
- interface ThreadsListPage {
32
- items: RemitImapThreadMessageResponse[];
33
- [key: string]: unknown;
34
- }
35
-
36
- interface ThreadsListData {
37
- pages: ThreadsListPage[];
38
- pageParams: Array<string | undefined>;
39
- }
32
+ /**
33
+ * Either shape a thread list/search query caches — the infinite mailbox list
34
+ * or a single-shot page. `setQueriesData` matches by key prefix, so the
35
+ * optimistic updater sees both.
36
+ */
37
+ type ThreadsListData = ThreadListCache;
40
38
 
41
39
  interface SnapshotEntry<T> {
42
40
  queryKey: readonly unknown[];
@@ -147,22 +145,16 @@ export const useDeleteMessages = ({
147
145
  );
148
146
  }
149
147
 
150
- const patchListData = (old: ThreadsListData | undefined) => {
151
- if (!old) return old;
152
- return {
153
- ...old,
154
- pages: old.pages.map((page) => ({
155
- ...page,
156
- items: removeMessagesFromItems(page.items, messageIds),
157
- })),
158
- };
159
- };
148
+ const patchListData = (old: unknown) =>
149
+ patchThreadListCache(old, (items) =>
150
+ removeMessagesFromItems(items, messageIds),
151
+ );
160
152
 
161
- queryClient.setQueriesData<ThreadsListData>(
153
+ queryClient.setQueriesData(
162
154
  { queryKey: threadsListPrefix },
163
155
  patchListData,
164
156
  );
165
- queryClient.setQueriesData<ThreadsListData>(
157
+ queryClient.setQueriesData(
166
158
  { queryKey: threadsSearchPrefix },
167
159
  patchListData,
168
160
  );
@@ -193,6 +185,7 @@ export const useDeleteMessages = ({
193
185
  ? `Couldn't delete ${count} messages`
194
186
  : "Couldn't delete this message",
195
187
  detail: formatErrorDetail(err),
188
+ error: err,
196
189
  });
197
190
  },
198
191
  onSettled: (_data, _err, _vars, context) => {
@@ -18,6 +18,10 @@ import { useQuery } from "@tanstack/react-query";
18
18
  import { useMemo } from "react";
19
19
  import { isServerError } from "@/lib/error-classifier";
20
20
  import { formatDate, formatEmailDate } from "@/lib/format";
21
+ import {
22
+ pickSenderAddress,
23
+ senderAddressSearchQuery,
24
+ } from "@/lib/sender-address";
21
25
 
22
26
  /**
23
27
  * Format a creation timestamp as a human-readable "first seen" label.
@@ -180,7 +184,11 @@ export interface UseIntelligenceDataResult {
180
184
  * that misrepresents the sender's real state. Escalation covers it.
181
185
  */
182
186
  addressErrorIsFatal: boolean;
183
- /** Address id for the sender — needed for PATCH /addresses/{id} mutations. */
187
+ /**
188
+ * Address id for the sender — needed for PATCH /addresses/{id} mutations.
189
+ * `undefined` until the lookup resolves the row for exactly this address;
190
+ * quick actions that PATCH it must stay unwired until then.
191
+ */
184
192
  addressId: string | undefined;
185
193
  /**
186
194
  * Raw address response for the sender — forwarded to the quick-action
@@ -209,13 +217,16 @@ export function useIntelligenceData(
209
217
  // --- Address lookup: flags + first-seen timestamp ---
210
218
  const { data: addressSearchResult, error: addressError } = useQuery({
211
219
  ...addressOperationsSearchAddressesOptions({
212
- query: { q: senderEmail ?? "", limit: 1 },
220
+ query: senderAddressSearchQuery(senderEmail ?? undefined),
213
221
  }),
214
222
  enabled: Boolean(senderEmail),
215
223
  staleTime: 30_000,
216
224
  });
217
225
 
218
- const address = addressSearchResult?.items?.[0];
226
+ const address = pickSenderAddress(
227
+ addressSearchResult?.items,
228
+ senderEmail ?? undefined,
229
+ );
219
230
 
220
231
  // --- Semantic search: similar messages ---
221
232
  const semanticQuery = [subject, senderEmail].filter(Boolean).join(" ");
@@ -10,6 +10,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
10
10
  import { useCallback, useEffect, useMemo, useRef } from "react";
11
11
  import { useErrorBanners } from "@/components/ui/ErrorBannerProvider";
12
12
  import { formatErrorDetail } from "@/components/ui/error-banners";
13
+ import { patchThreadListCache, type ThreadListCache } from "@/lib/thread-cache";
13
14
 
14
15
  interface UseMarkAsReadOptions {
15
16
  messages: RemitImapThreadMessageResponse[];
@@ -24,15 +25,12 @@ interface ThreadMessagesData {
24
25
  [key: string]: unknown;
25
26
  }
26
27
 
27
- interface ThreadsListPage {
28
- items: RemitImapThreadMessageResponse[];
29
- [key: string]: unknown;
30
- }
31
-
32
- interface ThreadsListData {
33
- pages: ThreadsListPage[];
34
- pageParams: Array<string | undefined>;
35
- }
28
+ /**
29
+ * Either shape a thread list/search query caches — the infinite mailbox list
30
+ * or a single-shot page. `setQueriesData` matches by key prefix, so the
31
+ * optimistic updater sees both.
32
+ */
33
+ type ThreadsListData = ThreadListCache;
36
34
 
37
35
  interface SnapshotEntry<T> {
38
36
  queryKey: readonly unknown[];
@@ -178,25 +176,16 @@ export const useMarkAsRead = ({
178
176
  },
179
177
  );
180
178
 
181
- const patchListData = (old: ThreadsListData | undefined) => {
182
- if (!old) return old;
183
- return {
184
- ...old,
185
- pages: old.pages.map((page) => ({
186
- ...page,
187
- items: setReadOnItems(page.items, messageIds, isRead),
188
- })),
189
- };
190
- };
179
+ const patchListData = (old: unknown) =>
180
+ patchThreadListCache(old, (items) =>
181
+ setReadOnItems(items, messageIds, isRead),
182
+ );
191
183
 
192
184
  for (const queryKey of [
193
185
  ...threadsListPrefixes,
194
186
  ...threadsSearchPrefixes,
195
187
  ]) {
196
- queryClient.setQueriesData<ThreadsListData>(
197
- { queryKey },
198
- patchListData,
199
- );
188
+ queryClient.setQueriesData({ queryKey }, patchListData);
200
189
  }
201
190
 
202
191
  return {
@@ -231,6 +220,7 @@ export const useMarkAsRead = ({
231
220
  pushError({
232
221
  title: isRead ? "Couldn't mark as read" : "Couldn't mark as unread",
233
222
  detail: formatErrorDetail(error),
223
+ error,
234
224
  });
235
225
  },
236
226
  onSettled: (_data, _err, _vars, context) => {
@@ -321,6 +311,7 @@ export const useToggleReadFor = (options: {
321
311
  pushError({
322
312
  title: isRead ? "Couldn't mark as read" : "Couldn't mark as unread",
323
313
  detail: formatErrorDetail(error),
314
+ error,
324
315
  });
325
316
  },
326
317
  onSettled: () => {
@@ -7,6 +7,7 @@ import {
7
7
  pickRenderablePart,
8
8
  type RenderableBodyPart,
9
9
  } from "@/lib/message-body-source";
10
+ import { taggedFetch } from "@/lib/network-error";
10
11
  import { useTelemetry } from "@/lib/telemetry-context";
11
12
  import { messageKeys } from "./queries/keys";
12
13
 
@@ -186,7 +187,7 @@ export const fetchBodyContent = async (
186
187
  const headers: Record<string, string> = {};
187
188
  const token = await getToken();
188
189
  if (token) headers.Authorization = `Bearer ${token}`;
189
- const response = await fetch(url, { headers });
190
+ const response = await taggedFetch(url, { headers });
190
191
  // 202 = the body is not synced yet. The content route has re-armed the sync
191
192
  // cue; retry after `Retry-After` seconds rather than rendering the placeholder
192
193
  // body (a 202 is `ok`, so this must be caught before the success path).
@@ -10,6 +10,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
10
10
  import { useCallback } from "react";
11
11
  import { useErrorBanners } from "@/components/ui/ErrorBannerProvider";
12
12
  import { formatErrorDetail } from "@/components/ui/error-banners";
13
+ import { patchThreadListCache, type ThreadListCache } from "@/lib/thread-cache";
13
14
 
14
15
  interface UseMoveMessagesOptions {
15
16
  mailboxId: string;
@@ -28,15 +29,12 @@ interface ThreadMessagesData {
28
29
  [key: string]: unknown;
29
30
  }
30
31
 
31
- interface ThreadsListPage {
32
- items: RemitImapThreadMessageResponse[];
33
- [key: string]: unknown;
34
- }
35
-
36
- interface ThreadsListData {
37
- pages: ThreadsListPage[];
38
- pageParams: Array<string | undefined>;
39
- }
32
+ /**
33
+ * Either shape a thread list/search query caches — the infinite mailbox list
34
+ * or a single-shot page. `setQueriesData` matches by key prefix, so the
35
+ * optimistic updater sees both.
36
+ */
37
+ type ThreadsListData = ThreadListCache;
40
38
 
41
39
  interface SnapshotEntry<T> {
42
40
  queryKey: readonly unknown[];
@@ -142,22 +140,16 @@ export const useMoveMessages = ({
142
140
  );
143
141
  }
144
142
 
145
- const patchListData = (old: ThreadsListData | undefined) => {
146
- if (!old) return old;
147
- return {
148
- ...old,
149
- pages: old.pages.map((page) => ({
150
- ...page,
151
- items: removeMovedMessagesFromItems(page.items, messageIds),
152
- })),
153
- };
154
- };
143
+ const patchListData = (old: unknown) =>
144
+ patchThreadListCache(old, (items) =>
145
+ removeMovedMessagesFromItems(items, messageIds),
146
+ );
155
147
 
156
- queryClient.setQueriesData<ThreadsListData>(
148
+ queryClient.setQueriesData(
157
149
  { queryKey: threadsListPrefix },
158
150
  patchListData,
159
151
  );
160
- queryClient.setQueriesData<ThreadsListData>(
152
+ queryClient.setQueriesData(
161
153
  { queryKey: threadsSearchPrefix },
162
154
  patchListData,
163
155
  );
@@ -188,6 +180,7 @@ export const useMoveMessages = ({
188
180
  ? `Couldn't move ${count} messages`
189
181
  : "Couldn't move this message",
190
182
  detail: formatErrorDetail(err),
183
+ error: err,
191
184
  });
192
185
  },
193
186
  onSettled: (_data, _err, _vars, context) => {
@@ -2,6 +2,7 @@ import assert from "node:assert/strict";
2
2
  import { afterEach, describe, test } from "node:test";
3
3
  import { ApiError } from "../lib/api.js";
4
4
  import { __resetFatalError, subscribeFatalError } from "../lib/fatal-error.js";
5
+ import { NetworkError } from "../lib/network-error.js";
5
6
  import {
6
7
  __peekStaleAccountSyncGuard,
7
8
  __resetStaleAccountSyncGuard,
@@ -227,11 +228,31 @@ describe("handleBackgroundSyncFailure", () => {
227
228
  escalated = true;
228
229
  });
229
230
 
230
- handleBackgroundSyncFailure("a-1", new TypeError("Failed to fetch"));
231
+ // The probe goes through the generated client, so a real transport
232
+ // failure arrives tagged by the fetch boundary.
233
+ handleBackgroundSyncFailure(
234
+ "a-1",
235
+ new NetworkError(new TypeError("Failed to fetch")),
236
+ );
231
237
 
232
238
  assert.equal(escalated, false);
233
239
  });
234
240
 
241
+ test("an exception from our own code on the probe DOES escalate", () => {
242
+ silenceWarn();
243
+ let escalated = false;
244
+ subscribeFatalError(() => {
245
+ escalated = true;
246
+ });
247
+
248
+ // Untagged and statusless: nothing said this came off the wire, so it is
249
+ // our bug, and a silent background probe is exactly where one would
250
+ // otherwise go unnoticed.
251
+ handleBackgroundSyncFailure("a-1", new TypeError("x is not a function"));
252
+
253
+ assert.equal(escalated, true);
254
+ });
255
+
235
256
  test("drops the per-account guard so a later remount can retry", () => {
236
257
  silenceWarn();
237
258
  __peekStaleAccountSyncGuard(); // touch to ensure import is used