Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enforce sensible defaults for react-query #268

Merged
merged 2 commits into from
Feb 6, 2025

Conversation

alex-mcgovern
Copy link
Collaborator

@alex-mcgovern alex-mcgovern commented Feb 5, 2025

This PR does a few things:

  • configures some global default settings for useQuery usage
    • data will refetch on reconnect, window focus and component mount
    • data is considered stale immediately after fetching (to support CRUD use cases)
  • alerts & converstations override the default cache behaviour and cache for 5s (as part of previous fix for bug with server-sent events)
  • adds eslint no-restricted-syntax rules that, in short:
    • disallow setting refetchOnMount, refetchOnReconnect & refetchOnWindowFocus on a per query basis
    • disallow configuring staleTime (cache) without using the shared abstraction in lib/react-query-utils
    • disallow setting queryFn and queryKey (force use of openapi-ts helpers, which simplifies/supports cache invalidation)
    • disallows directly calling QueryClient.invalidateQueries — forcing use of the invalidateQueries helper (which invalidates only stale queries, reducing unnecessary requests)
  • increases the interval at which we poll the health check & version endpoint to 60s (the version endpoint has a 20min cache anyway)
  • cleans up useQuery usage throughout the codebase to support the above changes

@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 13162444531

Details

  • 20 of 22 (90.91%) changed or added relevant lines in 11 files are covered.
  • 2 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.8%) to 70.24%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/features/providers/hooks/use-invalidate-providers-queries.ts 0 1 0.0%
src/features/workspace/components/workspaces-selection.tsx 0 1 0.0%
Files with Coverage Reduction New Missed Lines %
src/features/workspace/components/workspaces-selection.tsx 1 77.78%
src/components/react-query-provider.tsx 1 0.0%
Totals Coverage Status
Change from base Build 13160217968: 0.8%
Covered Lines: 821
Relevant Lines: 1104

💛 - Coveralls

@alex-mcgovern alex-mcgovern merged commit 5445eb6 into main Feb 6, 2025
9 checks passed
@alex-mcgovern alex-mcgovern deleted the feat/enforce-sensible-defaults-for-react-query branch February 6, 2025 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants