Skip to content

refactor: Don't return full tanstack query result#1827

Open
mfortman11 wants to merge 1 commit into
mainfrom
tanstack-query-return
Open

refactor: Don't return full tanstack query result#1827
mfortman11 wants to merge 1 commit into
mainfrom
tanstack-query-return

Conversation

@mfortman11

@mfortman11 mfortman11 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

When you write const queryResult = useQuery(...), TanStack Query hands you the full result object — but it has no way to know which fields you actually use. So it conservatively re-renders your component whenever any field changes (fetchStatus, dataUpdatedAt, internal counters, etc.), even if you only care about data and isLoading.

Summary by CodeRabbit

  • Refactor
    • Improved code quality and maintainability across the data query layer by streamlining multiple query management hooks. Refactored internal query structures to reduce unnecessary intermediate processing and improve code readability throughout the data fetching layer with no impact to existing functionality or performance.

@github-actions github-actions Bot added frontend 🟨 Issues related to the UI/UX community labels Jun 10, 2026
@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b8adebf0-57cd-449b-b341-28aae0d18d30

📥 Commits

Reviewing files that changed from the base of the PR and between 8530ab0 and 1ae0793.

📒 Files selected for processing (8)
  • frontend/app/api/queries/useDoclingHealthQuery.ts
  • frontend/app/api/queries/useGetConversationsQuery.ts
  • frontend/app/api/queries/useGetModelsQuery.ts
  • frontend/app/api/queries/useGetNudgesQuery.ts
  • frontend/app/api/queries/useGetSearchQuery.ts
  • frontend/app/api/queries/useGetSettingsQuery.ts
  • frontend/app/api/queries/useGetTasksQuery.ts
  • frontend/app/api/queries/useProviderHealthQuery.ts

Walkthrough

Eight React Query hooks across health checks, data retrieval, and provider-specific models are refactored to return useQuery(...) directly instead of storing results in intermediate variables. One hook (nudges) additionally explicitly destructures and selects specific query fields in its return value.

Changes

Query hooks direct return refactoring

Layer / File(s) Summary
Health and task management hooks
frontend/app/api/queries/useDoclingHealthQuery.ts, useProviderHealthQuery.ts, useGetTasksQuery.ts
Docling health, provider health, and tasks query hooks eliminate intermediate queryResult variable and return useQuery(...) directly. Query configuration and logic remain unchanged.
Data retrieval hooks
frontend/app/api/queries/useGetConversationsQuery.ts, useGetSearchQuery.ts, useGetSettingsQuery.ts
Conversations, search, and settings query hooks simplified by removing intermediate variable assignment and returning useQuery(...) directly, preserving all query keys, functions, and options.
Multi-provider models hooks
frontend/app/api/queries/useGetModelsQuery.ts
OpenAI, Anthropic, Ollama, and IBM provider-specific model query hooks refactored to directly return useQuery(...) instead of intermediate variable pattern, maintaining provider-specific fetch logic and caching configuration.
Nudges query selective fields
frontend/app/api/queries/useGetNudgesQuery.ts
Nudges hook destructures specific useQuery result fields (data, isLoading, isError, error, refetch, isFetching) and returns them explicitly with cancel function instead of spreading full queryResult object.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested labels

refactor

Suggested reviewers

  • mpawlow
  • edwinjosechittilappilly
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main refactoring objective: simplifying how TanStack Query results are returned to avoid unnecessary re-renders.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tanstack-query-return

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community frontend 🟨 Issues related to the UI/UX refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant