fix(presentation): stop reporting a disabled query as loading (R-8.8)
useApplicationQuery passed TanStack's isPending as isInitialLoading. A disabled query without data is pending (fetchStatus "idle"), so dependent queries waiting on a prerequisite showed a skeleton and aria-busy forever. Two changes were needed: - application-query.ts passes isPending && fetchStatus !== "idle". The review suggested isLoading, but with the default networkMode "online" an offline first load is "paused" (isFetching false), and isLoading would stop showing it as loading. - deriveAsyncState fell back to "initial-loading" whenever there was no data, no failure and no load, so the signal fix alone still produced initial-loading (checked). The fallback is now "empty". This also stops a query that resolves to null from looking like it loads forever. Verified: RED "does not report a disabled query without data as loading" failed with base "initial-loading" before and passes after; "still reports a real first load as loading, including a paused offline one" guards the other direction. check:architecture, check:types:app, check:types:test, lint, test:component pass; test:unit passes except the pre-existing removal-fixture test (needs generated artifacts/ files absent from a fresh worktree). test:reference-feature also passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
900659b32c
commit
3b3765cc49
@@ -95,7 +95,9 @@ export function deriveAsyncState(signals: AsyncSignals): AsyncState {
|
||||
? "empty"
|
||||
: hasData
|
||||
? "success"
|
||||
: "initial-loading";
|
||||
: // Nothing loading, failed or present (a disabled query) is not
|
||||
// a load in progress.
|
||||
"empty";
|
||||
|
||||
const indicator =
|
||||
signals.hasMutationEffectUnknown && hasData
|
||||
|
||||
@@ -177,7 +177,9 @@ export function useApplicationQuery<Value>(
|
||||
data: query.data,
|
||||
state: deriveAsyncState({
|
||||
data: query.data,
|
||||
isInitialLoading: query.isPending,
|
||||
// A disabled query is pending but idle; a paused offline first load is
|
||||
// pending and still waiting, which `isLoading` would miss.
|
||||
isInitialLoading: query.isPending && query.fetchStatus !== "idle",
|
||||
failure:
|
||||
!hasData && query.error instanceof ApplicationQueryError
|
||||
? query.error.failure
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// @vitest-environment jsdom
|
||||
|
||||
import { onlineManager } from "@tanstack/react-query";
|
||||
import { act, renderHook, waitFor } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
@@ -109,6 +110,54 @@ describe("application query inbound bridge", () => {
|
||||
expect(physicalRefetches).toBe(1);
|
||||
});
|
||||
|
||||
it("does not report a disabled query without data as loading", async () => {
|
||||
// A dependent query waiting on its prerequisite is idle, not loading.
|
||||
const client = queryClient();
|
||||
const execute = vi.fn(async () => ({ ok: true as const, value: ["x"] }));
|
||||
const hook = renderHook(
|
||||
() =>
|
||||
useApplicationQuery({
|
||||
queryKey: ["resource", "waiting-on-prerequisite"],
|
||||
execute,
|
||||
enabled: false,
|
||||
}),
|
||||
{ wrapper: wrapper(client) },
|
||||
);
|
||||
|
||||
expect(hook.result.current.state.base).not.toBe("initial-loading");
|
||||
expect(execute).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("still reports a real first load as loading, including a paused offline one", async () => {
|
||||
const client = queryClient();
|
||||
const execute = vi.fn(
|
||||
() => new Promise<ApplicationResult<string[]>>(() => {}),
|
||||
);
|
||||
const inFlight = renderHook(
|
||||
() => useApplicationQuery({ queryKey: ["resource", "first"], execute }),
|
||||
{ wrapper: wrapper(client) },
|
||||
);
|
||||
await waitFor(() => expect(execute).toHaveBeenCalledOnce());
|
||||
expect(inFlight.result.current.state.base).toBe("initial-loading");
|
||||
|
||||
// Offline, TanStack pauses the first fetch (isFetching=false) instead of
|
||||
// running it; the user is still waiting for data.
|
||||
onlineManager.setOnline(false);
|
||||
try {
|
||||
const paused = renderHook(
|
||||
() =>
|
||||
useApplicationQuery({ queryKey: ["resource", "offline"], execute }),
|
||||
{ wrapper: wrapper(client) },
|
||||
);
|
||||
expect(client.getQueryState(["resource", "offline"])?.fetchStatus).toBe(
|
||||
"paused",
|
||||
);
|
||||
expect(paused.result.current.state.base).toBe("initial-loading");
|
||||
} finally {
|
||||
onlineManager.setOnline(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("projects an initial application failure into terminal state", async () => {
|
||||
const client = queryClient();
|
||||
const failure = createFailure("FORBIDDEN", "LIST", 0);
|
||||
|
||||
Reference in New Issue
Block a user