@tanstack/react-query
Advanced tools
Comparing version 5.56.2 to 5.59.0
@@ -15,7 +15,7 @@ import { DefaultError, QueryKey, QueryObserverOptions, OmitKeyof, InfiniteQueryObserverOptions, QueryObserverResult, DefinedQueryObserverResult, InfiniteQueryObserverResult, DefinedInfiniteQueryObserverResult, MutationObserverOptions, MutateFunction, Override, MutationObserverResult } from '@tanstack/query-core'; | ||
type UseQueryResult<TData = unknown, TError = DefaultError> = UseBaseQueryResult<TData, TError>; | ||
type UseSuspenseQueryResult<TData = unknown, TError = DefaultError> = OmitKeyof<DefinedQueryObserverResult<TData, TError>, 'isPlaceholderData'>; | ||
type UseSuspenseQueryResult<TData = unknown, TError = DefaultError> = OmitKeyof<DefinedQueryObserverResult<TData, TError>, 'isPlaceholderData' | 'promise'>; | ||
type DefinedUseQueryResult<TData = unknown, TError = DefaultError> = DefinedQueryObserverResult<TData, TError>; | ||
type UseInfiniteQueryResult<TData = unknown, TError = DefaultError> = InfiniteQueryObserverResult<TData, TError>; | ||
type DefinedUseInfiniteQueryResult<TData = unknown, TError = DefaultError> = DefinedInfiniteQueryObserverResult<TData, TError>; | ||
type UseSuspenseInfiniteQueryResult<TData = unknown, TError = DefaultError> = OmitKeyof<DefinedInfiniteQueryObserverResult<TData, TError>, 'isPlaceholderData'>; | ||
type UseSuspenseInfiniteQueryResult<TData = unknown, TError = DefaultError> = OmitKeyof<DefinedInfiniteQueryObserverResult<TData, TError>, 'isPlaceholderData' | 'promise'>; | ||
interface UseMutationOptions<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> extends OmitKeyof<MutationObserverOptions<TData, TError, TVariables, TContext>, '_defaulted'> { | ||
@@ -22,0 +22,0 @@ } |
@@ -0,3 +1,3 @@ | ||
import { QueryKey, QueryObserver, QueryClient, QueryObserverResult } from '@tanstack/query-core'; | ||
import { UseBaseQueryOptions } from './types.js'; | ||
import { QueryKey, QueryObserver, QueryClient, QueryObserverResult } from '@tanstack/query-core'; | ||
@@ -4,0 +4,0 @@ declare function useBaseQuery<TQueryFnData, TError, TData, TQueryData, TQueryKey extends QueryKey>(options: UseBaseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>, Observer: typeof QueryObserver, queryClient?: QueryClient): QueryObserverResult<TData, TError>; |
@@ -5,6 +5,5 @@ "use client"; | ||
import * as React from "react"; | ||
import { notifyManager } from "@tanstack/query-core"; | ||
import { isServer, notifyManager } from "@tanstack/query-core"; | ||
import { useQueryClient } from "./QueryClientProvider.js"; | ||
import { useQueryErrorResetBoundary } from "./QueryErrorResetBoundary.js"; | ||
import { useQueryClient } from "./QueryClientProvider.js"; | ||
import { useIsRestoring } from "./isRestoring.js"; | ||
import { | ||
@@ -15,9 +14,12 @@ ensurePreventErrorBoundaryRetry, | ||
} from "./errorBoundaryUtils.js"; | ||
import { useIsRestoring } from "./isRestoring.js"; | ||
import { | ||
ensureSuspenseTimers, | ||
fetchOptimistic, | ||
shouldSuspend | ||
shouldSuspend, | ||
willFetch | ||
} from "./suspense.js"; | ||
import { noop } from "./utils.js"; | ||
function useBaseQuery(options, Observer, queryClient) { | ||
var _a, _b, _c, _d; | ||
var _a, _b, _c, _d, _e; | ||
if (process.env.NODE_ENV !== "production") { | ||
@@ -42,2 +44,3 @@ if (typeof options !== "object" || Array.isArray(options)) { | ||
useClearResetErrorBoundary(errorResetBoundary); | ||
const isNewCacheEntry = !client.getQueryState(options.queryKey); | ||
const [observer] = React.useState( | ||
@@ -82,2 +85,16 @@ () => new Observer( | ||
); | ||
if (defaultedOptions.experimental_prefetchInRender && !isServer && willFetch(result, isRestoring)) { | ||
const promise = isNewCacheEntry ? ( | ||
// Fetch immediately on render in order to ensure `.promise` is resolved even if the component is unmounted | ||
fetchOptimistic(defaultedOptions, observer, errorResetBoundary) | ||
) : ( | ||
// subscribe to the "cache promise" so that we can finalize the currentThenable once data comes in | ||
(_e = client.getQueryCache().get(defaultedOptions.queryHash)) == null ? void 0 : _e.promise | ||
); | ||
promise == null ? void 0 : promise.catch(noop).finally(() => { | ||
if (!observer.hasListeners()) { | ||
observer.updateResult(); | ||
} | ||
}); | ||
} | ||
return !defaultedOptions.notifyOnChangeProps ? observer.trackResult(result) : result; | ||
@@ -84,0 +101,0 @@ } |
@@ -15,7 +15,7 @@ import { DefaultError, QueryKey, QueryObserverOptions, OmitKeyof, InfiniteQueryObserverOptions, QueryObserverResult, DefinedQueryObserverResult, InfiniteQueryObserverResult, DefinedInfiniteQueryObserverResult, MutationObserverOptions, MutateFunction, Override, MutationObserverResult } from '@tanstack/query-core'; | ||
type UseQueryResult<TData = unknown, TError = DefaultError> = UseBaseQueryResult<TData, TError>; | ||
type UseSuspenseQueryResult<TData = unknown, TError = DefaultError> = OmitKeyof<DefinedQueryObserverResult<TData, TError>, 'isPlaceholderData'>; | ||
type UseSuspenseQueryResult<TData = unknown, TError = DefaultError> = OmitKeyof<DefinedQueryObserverResult<TData, TError>, 'isPlaceholderData' | 'promise'>; | ||
type DefinedUseQueryResult<TData = unknown, TError = DefaultError> = DefinedQueryObserverResult<TData, TError>; | ||
type UseInfiniteQueryResult<TData = unknown, TError = DefaultError> = InfiniteQueryObserverResult<TData, TError>; | ||
type DefinedUseInfiniteQueryResult<TData = unknown, TError = DefaultError> = DefinedInfiniteQueryObserverResult<TData, TError>; | ||
type UseSuspenseInfiniteQueryResult<TData = unknown, TError = DefaultError> = OmitKeyof<DefinedInfiniteQueryObserverResult<TData, TError>, 'isPlaceholderData'>; | ||
type UseSuspenseInfiniteQueryResult<TData = unknown, TError = DefaultError> = OmitKeyof<DefinedInfiniteQueryObserverResult<TData, TError>, 'isPlaceholderData' | 'promise'>; | ||
interface UseMutationOptions<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> extends OmitKeyof<MutationObserverOptions<TData, TError, TVariables, TContext>, '_defaulted'> { | ||
@@ -22,0 +22,0 @@ } |
@@ -0,3 +1,3 @@ | ||
import { QueryKey, QueryObserver, QueryClient, QueryObserverResult } from '@tanstack/query-core'; | ||
import { UseBaseQueryOptions } from './types.js'; | ||
import { QueryKey, QueryObserver, QueryClient, QueryObserverResult } from '@tanstack/query-core'; | ||
@@ -4,0 +4,0 @@ declare function useBaseQuery<TQueryFnData, TError, TData, TQueryData, TQueryKey extends QueryKey>(options: UseBaseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>, Observer: typeof QueryObserver, queryClient?: QueryClient): QueryObserverResult<TData, TError>; |
@@ -5,6 +5,5 @@ "use client"; | ||
import * as React from "react"; | ||
import { notifyManager } from "@tanstack/query-core"; | ||
import { isServer, notifyManager } from "@tanstack/query-core"; | ||
import { useQueryClient } from "./QueryClientProvider.js"; | ||
import { useQueryErrorResetBoundary } from "./QueryErrorResetBoundary.js"; | ||
import { useQueryClient } from "./QueryClientProvider.js"; | ||
import { useIsRestoring } from "./isRestoring.js"; | ||
import { | ||
@@ -15,7 +14,10 @@ ensurePreventErrorBoundaryRetry, | ||
} from "./errorBoundaryUtils.js"; | ||
import { useIsRestoring } from "./isRestoring.js"; | ||
import { | ||
ensureSuspenseTimers, | ||
fetchOptimistic, | ||
shouldSuspend | ||
shouldSuspend, | ||
willFetch | ||
} from "./suspense.js"; | ||
import { noop } from "./utils.js"; | ||
function useBaseQuery(options, Observer, queryClient) { | ||
@@ -40,2 +42,3 @@ if (process.env.NODE_ENV !== "production") { | ||
useClearResetErrorBoundary(errorResetBoundary); | ||
const isNewCacheEntry = !client.getQueryState(options.queryKey); | ||
const [observer] = React.useState( | ||
@@ -79,2 +82,16 @@ () => new Observer( | ||
); | ||
if (defaultedOptions.experimental_prefetchInRender && !isServer && willFetch(result, isRestoring)) { | ||
const promise = isNewCacheEntry ? ( | ||
// Fetch immediately on render in order to ensure `.promise` is resolved even if the component is unmounted | ||
fetchOptimistic(defaultedOptions, observer, errorResetBoundary) | ||
) : ( | ||
// subscribe to the "cache promise" so that we can finalize the currentThenable once data comes in | ||
client.getQueryCache().get(defaultedOptions.queryHash)?.promise | ||
); | ||
promise?.catch(noop).finally(() => { | ||
if (!observer.hasListeners()) { | ||
observer.updateResult(); | ||
} | ||
}); | ||
} | ||
return !defaultedOptions.notifyOnChangeProps ? observer.trackResult(result) : result; | ||
@@ -81,0 +98,0 @@ } |
{ | ||
"name": "@tanstack/react-query", | ||
"version": "5.56.2", | ||
"version": "5.59.0", | ||
"description": "Hooks for managing, caching and syncing asynchronous and remote data in React", | ||
@@ -44,3 +44,3 @@ "author": "tannerlinsley", | ||
"dependencies": { | ||
"@tanstack/query-core": "5.56.2" | ||
"@tanstack/query-core": "5.59.0" | ||
}, | ||
@@ -47,0 +47,0 @@ "devDependencies": { |
@@ -104,3 +104,6 @@ /* istanbul ignore file */ | ||
TError = DefaultError, | ||
> = OmitKeyof<DefinedQueryObserverResult<TData, TError>, 'isPlaceholderData'> | ||
> = OmitKeyof< | ||
DefinedQueryObserverResult<TData, TError>, | ||
'isPlaceholderData' | 'promise' | ||
> | ||
@@ -127,3 +130,3 @@ export type DefinedUseQueryResult< | ||
DefinedInfiniteQueryObserverResult<TData, TError>, | ||
'isPlaceholderData' | ||
'isPlaceholderData' | 'promise' | ||
> | ||
@@ -130,0 +133,0 @@ |
'use client' | ||
import * as React from 'react' | ||
import { notifyManager } from '@tanstack/query-core' | ||
import { isServer, notifyManager } from '@tanstack/query-core' | ||
import { useQueryClient } from './QueryClientProvider' | ||
import { useQueryErrorResetBoundary } from './QueryErrorResetBoundary' | ||
import { useQueryClient } from './QueryClientProvider' | ||
import { useIsRestoring } from './isRestoring' | ||
import { | ||
@@ -13,2 +12,3 @@ ensurePreventErrorBoundaryRetry, | ||
} from './errorBoundaryUtils' | ||
import { useIsRestoring } from './isRestoring' | ||
import { | ||
@@ -18,4 +18,5 @@ ensureSuspenseTimers, | ||
shouldSuspend, | ||
willFetch, | ||
} from './suspense' | ||
import type { UseBaseQueryOptions } from './types' | ||
import { noop } from './utils' | ||
import type { | ||
@@ -27,2 +28,3 @@ QueryClient, | ||
} from '@tanstack/query-core' | ||
import type { UseBaseQueryOptions } from './types' | ||
@@ -73,2 +75,5 @@ export function useBaseQuery< | ||
// this needs to be invoked before creating the Observer because that can create a cache entry | ||
const isNewCacheEntry = !client.getQueryState(options.queryKey) | ||
const [observer] = React.useState( | ||
@@ -138,2 +143,21 @@ () => | ||
if ( | ||
defaultedOptions.experimental_prefetchInRender && | ||
!isServer && | ||
willFetch(result, isRestoring) | ||
) { | ||
const promise = isNewCacheEntry | ||
? // Fetch immediately on render in order to ensure `.promise` is resolved even if the component is unmounted | ||
fetchOptimistic(defaultedOptions, observer, errorResetBoundary) | ||
: // subscribe to the "cache promise" so that we can finalize the currentThenable once data comes in | ||
client.getQueryCache().get(defaultedOptions.queryHash)?.promise | ||
promise?.catch(noop).finally(() => { | ||
if (!observer.hasListeners()) { | ||
// `.updateResult()` will trigger `.#currentThenable` to finalize | ||
observer.updateResult() | ||
} | ||
}) | ||
} | ||
// Handle result property usage tracking | ||
@@ -140,0 +164,0 @@ return !defaultedOptions.notifyOnChangeProps |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1145957
22971
+ Added@tanstack/query-core@5.59.0(transitive)
- Removed@tanstack/query-core@5.56.2(transitive)
Updated@tanstack/query-core@5.59.0