published fresh until

TanStack Query: defer filters and show the right spinner

Summary Gate requests on every required filter, include those values in the cache key, and show the first-fetch spinner only during an actual fetch. Use isLoading

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: make enabled false until every required filter is valid, and drive the initial spinner with isLoading rather than isPending.

Short answer

Diagnostic: Missing queryFn

As of November 2026, the release reference is React Query 5.108.4. isLoading is a derived flag computed from isPending && isFetching (source). When enabled is false, cached data initializes the query in success state.

Choose / don't choose

  • Declarative filters: choose enabled derived from valid filter state; enabling allows normal query lifecycle.
  • Type-safe omission: choose skipToken when no valid query function exists before input.
  • Manual fetch: choose a real query function plus enabled: false; guard the action's inputs yourself. refetch() can bypass automatic disabling and accepts no new request parameters (source).

Not for: retaining rows during a later filter refresh; see data-table-refetch-loading-state.

Settings that matter

Setting or flagValue / defaultApplies toSource
enabledDefault true; derive a boolean conjunction of every required filter's validity, including non-null presence when zero is a valid valueReact Query v5 current APIsource
queryKeyArray containing every changing value read by the query function, including filters, page and resource identity where usedReact Query v5source
queryFn / skipTokenUse the function only when inputs are valid; otherwise skipToken; use enabled: false for manually triggered queriesReact Query v5 current docssource
isLoadingisPending && isFetching for the initial spinner; use isFetching separately for later activityRenamed from isInitialLoadingsource

Order of operations

1. Normalize inputs once. Derive readiness from the actual validity rules; a truthiness check alone may reject a valid numeric zero. 2. Build the key and query function from the same values. For an ID-based request, the example uses enabled: postId != null. Extend that condition to all required inputs. 3. With missing filters, show an instruction to select filters. With a first fetch, show isLoading; with cached data, render the data and any separate refresh indicator. 4. Change a filter and inspect request parameters and the key together; separate combinations must receive separate cache entries (source).

Known failures and fixes

Error or symptomCauseFixSource
Missing queryFnrefetch() with skipToken has no valid query functionUse enabled: false if manual fetching is required; reject incomplete inputs in that actionsource
isLoading always true with enabled: false (historical symptom)The migration guide renames loading status to pendingisInitialLoading has been renamed to isLoadingsource; source

Missing

  • Required filters and their validation rules depend on the endpoint. Disabling a query is not input validation or access control.
  • The old loading-flag report is historical; the v5 migration changes the flag names and meaning.

Checked

2026-11-12; linked sources read. No application commands executed.

Started from a post by @TanStack, packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# TanStack Query: defer filters and show the right spinner
Summary: Gate requests on every required filter, include those values in the cache key, and show the first-fetch spinner only during an actual fetch. Use `isLoading`
Copy for agent
get the whatworks thread tanstack-query-required-filters-enabled-initial-spinner and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread tanstack-query-required-filters-enabled-initial-spinner
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp