Skip to content

feat(react): support react-query v4 alongside v5#300

Open
chakrihacker wants to merge 5 commits into
mainfrom
feat/tanstack-v4-support
Open

feat(react): support react-query v4 alongside v5#300
chakrihacker wants to merge 5 commits into
mainfrom
feat/tanstack-v4-support

Conversation

@chakrihacker
Copy link
Copy Markdown
Contributor

@chakrihacker chakrihacker commented May 25, 2026

Summary

Adds React Query v4 compatibility to packages/react so consumers on @tanstack/react-query v4 or v5 can use the library without a version conflict.

  • move @tanstack/react-query to peer dependencies to allow v4 and v5
  • fallback to mutation.isLoading when isPending is undefined for v4 compatibility
  • add cacheTime configuration alongside gcTime to support v4 cache

Why

@tanstack/react-query was a hard dependency pinned to v5, which blocked consumers already on v4 from adopting the library. Relying on a single major version also made the package incompatible with projects that cannot easily migrate past the v4→v5 breaking API changes (isPending, gcTime, keepPreviousData).

What

  • @tanstack/react-query moved from dependencies to peerDependencies with range ^4.36.1 || ^5.0.0; v5 retained as a devDependency for local builds and tests
  • QueryCacheConfig now includes cacheTime alongside gcTime; DEFAULT_CACHE_CONFIG and createQueryClient populate both so the QueryClient works under either major version
  • Mutation isPending (v5) replaced with isPending ?? (mutation as any).isLoading across all hooks that expose loading states (use-user-mfa, use-domain-table, use-sso-domain-tab, use-sso-provider-create, use-sso-provider-edit, use-sso-provider-table-service, use-organization-details-edit)

Packages

  • packages/core
  • packages/react
  • examples

References

Testing

How can this be verified? Note anything intentionally not covered by tests and why.

  • This change adds unit test coverage
  • Tested for both SPA and RWA flows, all example apps working
  • All existing and new tests complete without errors

Checklist

  • Breaking change
  • Requires docs update
  • Backward compatible

Contributing

- move @tanstack/react-query to peer dependencies to allow v4 and v5
- fallback to mutation.isLoading when isPending is undefined for v4 compatibility
- add cacheTime configuration alongside gcTime to support v4 cache
- ignore .mcp.json in git
@chakrihacker chakrihacker marked this pull request as ready for review May 25, 2026 19:52
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 25, 2026

Codecov Report

❌ Patch coverage is 88.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.45%. Comparing base (eaf02f9) to head (e35bbd1).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
packages/react/src/lib/utils/tanstack-compat.ts 54.54% 5 Missing ⚠️
...ackages/react/src/hooks/my-account/use-user-mfa.ts 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #300      +/-   ##
==========================================
- Coverage   89.47%   89.45%   -0.03%     
==========================================
  Files         156      157       +1     
  Lines       13070    13091      +21     
  Branches     1419     1729     +310     
==========================================
+ Hits        11694    11710      +16     
- Misses       1376     1381       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread packages/react/package.json Outdated
"react-dom": "^16.11.0 || ^17 || ^18 || ^19.2.1",
"react-hook-form": "^7.0.0"
"react-hook-form": "^7.0.0",
"@tanstack/react-query": "^4.36.1 || ^5.0.0"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the initial requirement was to not have peer dependency, we should be able to provide an override from consume for specific use cases


const handleCancelDelete = useCallback(() => {
if (deleteMutation.isPending) return;
if (deleteMutation.isPending ?? (deleteMutation as any).isLoading) return;
Copy link
Copy Markdown
Contributor

@rax7389 rax7389 May 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to make it more type safe

`import type { UseMutationResult } from '@tanstack/react-query';

type MutationV4Compat = { isLoading?: boolean };

export function isMutationPending<T extends Pick<UseMutationResult, 'isPending'> & MutationV4Compat>(
mutation: T
): boolean {
return mutation.isPending ?? mutation.isLoading ?? false;
}`

setIsDeleteDialogOpen(false);
setFactorToDelete(null);
}, [deleteMutation.isPending]);
}, [isMutationPending(deleteMutation)]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we only have **deleteMutation**

Comment thread .gitignore Outdated

# Generated API documentation
docs-api/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be removed?

Copy link
Copy Markdown
Contributor

@rax7389 rax7389 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#299

similar from this

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.

3 participants