Skip to content

Commit df6e902

Browse files
committed
refactor(frontend): trim comments to one line each
Every docblock in the new query layer said in a paragraph what fits on a line. Now: keys.ts 1 line, staleTime 1, queryClient 2, the converted hooks 1-3 each. DesktopQueryCacheReset keeps the most because the two things it encodes are both non-obvious — why a key can outlive its backend, and why resetQueries rather than clear(). No code change.
1 parent c1bd515 commit df6e902

13 files changed

Lines changed: 24 additions & 75 deletions

File tree

frontend/editor/src/core/api/config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ export async function fetchFooterInfo(): Promise<FooterInfo> {
1818
);
1919
return response.data;
2020
} catch (error) {
21-
// Toasts are suppressed here, so without this the failure is silent.
21+
// Toasts are suppressed here, so the failure would otherwise be silent.
2222
console.error("[api/config] footer-info failed:", error);
2323
throw error;
2424
}
2525
}
2626

27-
/** Whether a named backend feature group (ImageMagick, Calibre, ...) is available. */
2827
export async function fetchGroupEnabled(group: string): Promise<boolean> {
2928
const response = await apiClient.get<boolean>(
3029
`/api/v1/config/group-enabled?group=${encodeURIComponent(group)}`,

frontend/editor/src/core/api/users.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { UserSummary } from "@app/types/signingSession";
33

44
export async function fetchUsers(): Promise<UserSummary[]> {
55
const response = await apiClient.get<UserSummary[]>("/api/v1/user/users");
6-
// A proxy can answer 200 with an HTML login page; callers filter and sort
7-
// this, so a non-array body would throw during render.
6+
// A proxy can answer 200 with an HTML login page; callers assume an array.
87
return Array.isArray(response.data) ? response.data : [];
98
}

frontend/editor/src/core/hooks/useFooterInfo.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ import { CONFIG_STALE_TIME } from "@app/query/staleTime";
55

66
export type { FooterInfo };
77

8-
/** Analytics off is the safe read when the server can't be asked. */
98
const FALLBACK: FooterInfo = { analyticsEnabled: false };
109

11-
/** Public footer configuration. Shared by Footer and the admin legal section. */
10+
/** Public footer config, shared by Footer and the admin legal section. */
1211
export function useFooterInfo() {
1312
const { data, isPending, error } = useQuery({
1413
queryKey: qk.footerInfo(),
@@ -17,7 +16,7 @@ export function useFooterInfo() {
1716
});
1817

1918
return {
20-
// Callers read legal links off this, so a failure must still yield an object.
19+
// Callers render legal links off this, so a failure must still yield an object.
2120
footerInfo: data ?? (error ? FALLBACK : null),
2221
loading: isPending,
2322
error: (error as Error | null) ?? null,

frontend/editor/src/core/hooks/useGroupEnabled.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ import type { GroupEnabledResult } from "@app/types/groupEnabled";
66

77
export type { GroupEnabledResult };
88

9-
/**
10-
* Whether a named feature group is enabled on the backend.
11-
* `enabled` is null while loading; a failed check reads as disabled.
12-
*/
9+
/** Null while loading; a failed check reads as disabled. */
1310
export function useGroupEnabled(group: string): GroupEnabledResult {
1411
const { data, isPending } = useQuery({
1512
queryKey: qk.groupEnabled(group),

frontend/editor/src/core/query/keys.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
/**
2-
* Query keys for the editor: ["editor", <resource>, ...params].
3-
*
4-
* Keys are flavour-agnostic — which backend answers is decided by the api
5-
* layer, and on desktop by operationRouter at request time. A key therefore
6-
* does not pin a backend; see DesktopQueryCacheReset.
7-
*/
1+
/** Editor query keys: ["editor", <resource>, ...params]. */
82
export const qk = {
93
footerInfo: () => ["editor", "footerInfo"] as const,
104
groupEnabled: (group: string) => ["editor", "groupEnabled", group] as const,

frontend/editor/src/core/query/queryClient.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import { QueryClient, type DefaultOptions } from "@tanstack/react-query";
22

3-
/**
4-
* Query defaults for every client in the app, editor and Processor alike.
5-
*
6-
* networkMode "always" because navigator.onLine tracks internet reachability,
7-
* which says nothing about a bundled backend on 127.0.0.1 or a self-hosted
8-
* server on the LAN. On Query's default, losing Wi-Fi strands every query
9-
* pending against a backend that is up.
10-
*/
3+
// networkMode "always": navigator.onLine tracks the internet, not a backend on
4+
// 127.0.0.1 or the LAN. On the default, losing Wi-Fi strands every query.
115
export const baseQueryOptions: DefaultOptions["queries"] = {
126
staleTime: 30_000,
137
gcTime: 5 * 60_000,
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,2 @@
1-
/**
2-
* staleTime for server config lookups. A web build talks to one backend for its
3-
* whole life, and changing these server-side already needs a restart.
4-
*
5-
* Only for values that are the same for every user — there is no invalidation
6-
* on login/logout. Desktop shadows this; it cannot assume a single backend.
7-
*/
1+
/** Server config, fixed for the session. Nothing auth-scoped — no login/logout invalidation exists. */
82
export const CONFIG_STALE_TIME = Infinity;

frontend/editor/src/desktop/components/AppProviders.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,7 @@ export function AppProviders({ children }: { children: ReactNode }) {
312312
autoFetch: false,
313313
}}
314314
>
315-
{/* Also here: the auth check below switches mode before authChecked
316-
flips, and those switches must not be missed. */}
315+
{/* Also here: the auth check below switches mode pre-authChecked. */}
317316
<DesktopQueryCacheReset />
318317
<div style={{ minHeight: "100vh" }} />
319318
{updatePopupModal}

frontend/editor/src/desktop/components/DesktopQueryCacheReset.test.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ describe("DesktopQueryCacheReset", () => {
7070

7171
modeListeners.forEach((l) => l({ mode: "selfhosted" }));
7272

73-
// The mounted observer must be notified and refetch — evicting the entry
74-
// without notifying would leave the stale value on screen.
73+
// Must refetch, not just evict — this is what clear() got wrong.
7574
await waitFor(() => expect(seen).toContain("self-hosted-backend"));
7675
expect(queryFn).toHaveBeenCalledTimes(2);
7776
});
@@ -96,7 +95,6 @@ describe("DesktopQueryCacheReset", () => {
9695
renderWithConsumer(queryFn);
9796
await waitFor(() => expect(queryFn).toHaveBeenCalledTimes(1));
9897

99-
// No transition happened, so nothing should have been reset.
10098
expect(queryFn).toHaveBeenCalledTimes(1);
10199
});
102100
});

frontend/editor/src/desktop/components/DesktopQueryCacheReset.tsx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,20 @@ import { connectionModeService } from "@app/services/connectionModeService";
44
import { selfHostedServerMonitor } from "@app/services/selfHostedServerMonitor";
55

66
/**
7-
* Discards cached responses when the backend they came from stops being the one
8-
* the app talks to.
9-
*
10-
* A key does not pin a backend on desktop: operationRouter resolves the same
11-
* path to the bundled backend, a self-hosted server or the SaaS backend. Two
12-
* things move that target — a connection-mode switch, and the self-hosted
13-
* server going up or down, which reroutes with no mode event.
14-
*
15-
* resetQueries, not clear(): clear() evicts without notifying mounted
16-
* observers, so a panel keeps rendering the old backend's answer.
7+
* Drops cached responses when the backend behind them changes. operationRouter
8+
* resolves the same path to the bundled backend, a self-hosted server or SaaS,
9+
* so a mode switch or the server going up/down invalidates every key.
1710
*/
1811
export function DesktopQueryCacheReset() {
1912
const queryClient = useQueryClient();
2013

2114
useEffect(() => {
15+
// resetQueries, not clear(): clear() evicts without notifying mounted
16+
// observers, so a panel keeps rendering the old backend's answer.
2217
const reset = () => void queryClient.resetQueries();
2318
const unsubscribeMode = connectionModeService.subscribeToModeChanges(reset);
2419

25-
// Only offline<->reachable matters; the monitor also emits idle and
26-
// checking, and replays current state on subscribe.
20+
// Ignore idle/checking, and the state replayed on subscribe.
2721
let wasOffline: boolean | null = null;
2822
const unsubscribeServer = selfHostedServerMonitor.subscribe(
2923
({ status }) => {

0 commit comments

Comments
 (0)