8000 fix(react): allow using `enabled` when using `useQuery().promise` by arvi18 · Pull Request #7 · coderabbit-test/query · GitHub
[go: up one dir, main page]

Skip to content

fix(react): allow using enabled when using useQuery().promise #7

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
meep
  • Loading branch information
KATT committed Jan 6, 2025
commit f1daa83c2edf93647e7cbf538f74860f3f7a0b71
2 changes: 1 addition & 1 deletion packages/react-query/src/useBaseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export function useBaseQuery<
!isServer &&
willFetch(result, isRestoring)
) {
// This fetching in the render should likely be done as part of the getOptimisticResult() considering https://github.com/TanStack/query/issues/8507
Copy link

Choose a reason for hiding this comment

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

Logic Issue: The condition for shouldFetch has been modified to check cache entry state, but the comment "This fetching in the render should likely be done as part of the getOptimisticResult() considering TanStack#8507" suggests this may be a temporary solution. Consider addressing this architectural improvement in a future PR to ensure proper separation of concerns and better maintainability.

const cacheEntryState = cacheEntry?.state

const shouldFetch =
Expand All @@ -162,7 +163,6 @@ export function useBaseQuery<
cacheEntryState.status === 'pending' &&
cacheEntryState.fetchStatus === 'idle')

console.log({ shouldFetch })
const promise = shouldFetch
? // Fetch immediately on render in order to ensure `.promise` is resolved even if the component is unmounted
fetchOptimistic(defaultedOptions, observer, errorResetBoundary)
Expand Down
0