From 3b3765cc49935256167761b82d844ce0c751c780 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Thu, 24 Sep 2026 12:11:09 +0900 Subject: [PATCH] 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 --- src/application/view-models/async-state.ts | 4 +- .../adapters/query/application-query.ts | 4 +- .../application-query-bridge.test.tsx | 49 +++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/application/view-models/async-state.ts b/src/application/view-models/async-state.ts index 3a30cde2..ecea1f9f 100644 --- a/src/application/view-models/async-state.ts +++ b/src/application/view-models/async-state.ts @@ -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 diff --git a/src/presentation/adapters/query/application-query.ts b/src/presentation/adapters/query/application-query.ts index 48bca904..696869f0 100644 --- a/src/presentation/adapters/query/application-query.ts +++ b/src/presentation/adapters/query/application-query.ts @@ -177,7 +177,9 @@ export function useApplicationQuery( 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 diff --git a/tests/component/application-query-bridge.test.tsx b/tests/component/application-query-bridge.test.tsx index c22f766d..03edce88 100644 --- a/tests/component/application-query-bridge.test.tsx +++ b/tests/component/application-query-bridge.test.tsx @@ -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>(() => {}), + ); + 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);