@tanstack/preact-query 5.104.3 → 5.104.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/legacy/errorBoundaryUtils.cjs +1 -1
- package/build/legacy/errorBoundaryUtils.cjs.map +1 -1
- package/build/legacy/errorBoundaryUtils.d.cts.map +1 -1
- package/build/legacy/errorBoundaryUtils.d.ts.map +1 -1
- package/build/legacy/errorBoundaryUtils.js +1 -1
- package/build/legacy/errorBoundaryUtils.js.map +1 -1
- package/build/legacy/index.cjs +0 -1
- package/build/legacy/index.cjs.map +1 -1
- package/build/legacy/index.d.cts +1 -1
- package/build/legacy/index.d.ts +1 -1
- package/build/legacy/index.js +0 -1
- package/build/legacy/index.js.map +1 -1
- package/build/legacy/useBaseQuery.cjs +3 -2
- package/build/legacy/useBaseQuery.cjs.map +1 -1
- package/build/legacy/useBaseQuery.js +3 -2
- package/build/legacy/useBaseQuery.js.map +1 -1
- package/build/legacy/useMutationState.cjs +23 -20
- package/build/legacy/useMutationState.cjs.map +1 -1
- package/build/legacy/useMutationState.d.cts.map +1 -1
- package/build/legacy/useMutationState.d.ts.map +1 -1
- package/build/legacy/useMutationState.js +24 -21
- package/build/legacy/useMutationState.js.map +1 -1
- package/build/modern/errorBoundaryUtils.cjs +1 -1
- package/build/modern/errorBoundaryUtils.cjs.map +1 -1
- package/build/modern/errorBoundaryUtils.d.cts.map +1 -1
- package/build/modern/errorBoundaryUtils.d.ts.map +1 -1
- package/build/modern/errorBoundaryUtils.js +1 -1
- package/build/modern/errorBoundaryUtils.js.map +1 -1
- package/build/modern/index.cjs +0 -1
- package/build/modern/index.cjs.map +1 -1
- package/build/modern/index.d.cts +1 -1
- package/build/modern/index.d.ts +1 -1
- package/build/modern/index.js +0 -1
- package/build/modern/index.js.map +1 -1
- package/build/modern/useBaseQuery.cjs +3 -2
- package/build/modern/useBaseQuery.cjs.map +1 -1
- package/build/modern/useBaseQuery.js +3 -2
- package/build/modern/useBaseQuery.js.map +1 -1
- package/build/modern/useMutationState.cjs +23 -20
- package/build/modern/useMutationState.cjs.map +1 -1
- package/build/modern/useMutationState.d.cts.map +1 -1
- package/build/modern/useMutationState.d.ts.map +1 -1
- package/build/modern/useMutationState.js +24 -21
- package/build/modern/useMutationState.js.map +1 -1
- package/package.json +3 -3
- package/src/errorBoundaryUtils.ts +6 -2
- package/src/index.ts +1 -1
- package/src/useBaseQuery.ts +6 -2
- package/src/useMutationState.ts +52 -41
package/build/modern/index.cjs
CHANGED
|
@@ -3,7 +3,6 @@ const require_QueryClientProvider = require("./QueryClientProvider.cjs");
|
|
|
3
3
|
const require_HydrationBoundary = require("./HydrationBoundary.cjs");
|
|
4
4
|
const require_IsRestoringProvider = require("./IsRestoringProvider.cjs");
|
|
5
5
|
const require_QueryErrorResetBoundary = require("./QueryErrorResetBoundary.cjs");
|
|
6
|
-
require("./types.cjs");
|
|
7
6
|
const require_useQueries = require("./useQueries.cjs");
|
|
8
7
|
const require_useQuery = require("./useQuery.cjs");
|
|
9
8
|
const require_useSuspenseQuery = require("./useSuspenseQuery.cjs");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/index.ts"],"sourcesContent":["/* istanbul ignore file */\n\n// Re-export core\nexport * from '@tanstack/query-core'\n\n// Preact Query\nexport * from './types'\nexport { useQueries } from './useQueries'\nexport type { QueriesResults, QueriesOptions } from './useQueries'\nexport { useQuery } from './useQuery'\nexport { useSuspenseQuery } from './useSuspenseQuery'\nexport { useSuspenseInfiniteQuery } from './useSuspenseInfiniteQuery'\nexport { useSuspenseQueries } from './useSuspenseQueries'\nexport type {\n SuspenseQueriesResults,\n SuspenseQueriesOptions,\n} from './useSuspenseQueries'\nexport { usePrefetchQuery } from './usePrefetchQuery'\nexport { usePrefetchInfiniteQuery } from './usePrefetchInfiniteQuery'\nexport { queryOptions } from './queryOptions'\nexport type {\n DefinedInitialDataOptions,\n UndefinedInitialDataOptions,\n UnusedSkipTokenOptions,\n} from './queryOptions'\nexport { infiniteQueryOptions } from './infiniteQueryOptions'\nexport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n UnusedSkipTokenInfiniteOptions,\n} from './infiniteQueryOptions'\nexport {\n QueryClientContext,\n QueryClientProvider,\n useQueryClient,\n} from './QueryClientProvider'\nexport type { QueryClientProviderProps } from './QueryClientProvider'\nexport type { QueryErrorResetBoundaryProps } from './QueryErrorResetBoundary'\nexport { HydrationBoundary } from './HydrationBoundary'\nexport type { HydrationBoundaryProps } from './HydrationBoundary'\nexport type {\n QueryErrorClearResetFunction,\n QueryErrorIsResetFunction,\n QueryErrorResetBoundaryFunction,\n QueryErrorResetFunction,\n} from './QueryErrorResetBoundary'\nexport {\n QueryErrorResetBoundary,\n useQueryErrorResetBoundary,\n} from './QueryErrorResetBoundary'\nexport { useIsFetching } from './useIsFetching'\nexport { useIsMutating, useMutationState } from './useMutationState'\nexport { useMutation } from './useMutation'\nexport { mutationOptions } from './mutationOptions'\nexport { useInfiniteQuery } from './useInfiniteQuery'\nexport { useIsRestoring, IsRestoringProvider } from './IsRestoringProvider'\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/index.ts"],"sourcesContent":["/* istanbul ignore file */\n\n// Re-export core\nexport * from '@tanstack/query-core'\n\n// Preact Query\nexport type * from './types'\nexport { useQueries } from './useQueries'\nexport type { QueriesResults, QueriesOptions } from './useQueries'\nexport { useQuery } from './useQuery'\nexport { useSuspenseQuery } from './useSuspenseQuery'\nexport { useSuspenseInfiniteQuery } from './useSuspenseInfiniteQuery'\nexport { useSuspenseQueries } from './useSuspenseQueries'\nexport type {\n SuspenseQueriesResults,\n SuspenseQueriesOptions,\n} from './useSuspenseQueries'\nexport { usePrefetchQuery } from './usePrefetchQuery'\nexport { usePrefetchInfiniteQuery } from './usePrefetchInfiniteQuery'\nexport { queryOptions } from './queryOptions'\nexport type {\n DefinedInitialDataOptions,\n UndefinedInitialDataOptions,\n UnusedSkipTokenOptions,\n} from './queryOptions'\nexport { infiniteQueryOptions } from './infiniteQueryOptions'\nexport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n UnusedSkipTokenInfiniteOptions,\n} from './infiniteQueryOptions'\nexport {\n QueryClientContext,\n QueryClientProvider,\n useQueryClient,\n} from './QueryClientProvider'\nexport type { QueryClientProviderProps } from './QueryClientProvider'\nexport type { QueryErrorResetBoundaryProps } from './QueryErrorResetBoundary'\nexport { HydrationBoundary } from './HydrationBoundary'\nexport type { HydrationBoundaryProps } from './HydrationBoundary'\nexport type {\n QueryErrorClearResetFunction,\n QueryErrorIsResetFunction,\n QueryErrorResetBoundaryFunction,\n QueryErrorResetFunction,\n} from './QueryErrorResetBoundary'\nexport {\n QueryErrorResetBoundary,\n useQueryErrorResetBoundary,\n} from './QueryErrorResetBoundary'\nexport { useIsFetching } from './useIsFetching'\nexport { useIsMutating, useMutationState } from './useMutationState'\nexport { useMutation } from './useMutation'\nexport { mutationOptions } from './mutationOptions'\nexport { useInfiniteQuery } from './useInfiniteQuery'\nexport { useIsRestoring, IsRestoringProvider } from './IsRestoringProvider'\n"],"mappings":""}
|
package/build/modern/index.d.cts
CHANGED
|
@@ -18,4 +18,4 @@ import { useMutation } from "./useMutation.cjs";
|
|
|
18
18
|
import { mutationOptions } from "./mutationOptions.cjs";
|
|
19
19
|
import { useInfiniteQuery } from "./useInfiniteQuery.cjs";
|
|
20
20
|
export * from "@tanstack/query-core";
|
|
21
|
-
export { AnyUseBaseQueryOptions, AnyUseInfiniteQueryOptions, AnyUseMutationOptions, AnyUseQueryOptions, AnyUseSuspenseInfiniteQueryOptions, AnyUseSuspenseQueryOptions, type DefinedInitialDataInfiniteOptions, type DefinedInitialDataOptions, DefinedUseInfiniteQueryResult, DefinedUseQueryResult, HydrationBoundary, type HydrationBoundaryProps, IsRestoringProvider, type QueriesOptions, type QueriesResults, QueryClientContext, QueryClientProvider, type QueryClientProviderProps, type QueryErrorClearResetFunction, type QueryErrorIsResetFunction, QueryErrorResetBoundary, type QueryErrorResetBoundaryFunction, type QueryErrorResetBoundaryProps, type QueryErrorResetFunction, type SuspenseQueriesOptions, type SuspenseQueriesResults, type UndefinedInitialDataInfiniteOptions, type UndefinedInitialDataOptions, type UnusedSkipTokenInfiniteOptions, type UnusedSkipTokenOptions, UseBaseMutationResult, UseBaseQueryOptions, UseBaseQueryResult, UseInfiniteQueryOptions, UseInfiniteQueryResult, UseMutateAsyncFunction, UseMutateFunction, UseMutationOptions, UseMutationResult, UsePrefetchInfiniteQueryOptions, UsePrefetchQueryOptions, UseQueryOptions, UseQueryResult, UseSuspenseInfiniteQueryOptions, UseSuspenseInfiniteQueryResult, UseSuspenseQueryOptions, UseSuspenseQueryResult, infiniteQueryOptions, mutationOptions, queryOptions, useInfiniteQuery, useIsFetching, useIsMutating, useIsRestoring, useMutation, useMutationState, usePrefetchInfiniteQuery, usePrefetchQuery, useQueries, useQuery, useQueryClient, useQueryErrorResetBoundary, useSuspenseInfiniteQuery, useSuspenseQueries, useSuspenseQuery };
|
|
21
|
+
export { type AnyUseBaseQueryOptions, type AnyUseInfiniteQueryOptions, type AnyUseMutationOptions, type AnyUseQueryOptions, type AnyUseSuspenseInfiniteQueryOptions, type AnyUseSuspenseQueryOptions, type DefinedInitialDataInfiniteOptions, type DefinedInitialDataOptions, type DefinedUseInfiniteQueryResult, type DefinedUseQueryResult, HydrationBoundary, type HydrationBoundaryProps, IsRestoringProvider, type QueriesOptions, type QueriesResults, QueryClientContext, QueryClientProvider, type QueryClientProviderProps, type QueryErrorClearResetFunction, type QueryErrorIsResetFunction, QueryErrorResetBoundary, type QueryErrorResetBoundaryFunction, type QueryErrorResetBoundaryProps, type QueryErrorResetFunction, type SuspenseQueriesOptions, type SuspenseQueriesResults, type UndefinedInitialDataInfiniteOptions, type UndefinedInitialDataOptions, type UnusedSkipTokenInfiniteOptions, type UnusedSkipTokenOptions, type UseBaseMutationResult, type UseBaseQueryOptions, type UseBaseQueryResult, type UseInfiniteQueryOptions, type UseInfiniteQueryResult, type UseMutateAsyncFunction, type UseMutateFunction, type UseMutationOptions, type UseMutationResult, type UsePrefetchInfiniteQueryOptions, type UsePrefetchQueryOptions, type UseQueryOptions, type UseQueryResult, type UseSuspenseInfiniteQueryOptions, type UseSuspenseInfiniteQueryResult, type UseSuspenseQueryOptions, type UseSuspenseQueryResult, infiniteQueryOptions, mutationOptions, queryOptions, useInfiniteQuery, useIsFetching, useIsMutating, useIsRestoring, useMutation, useMutationState, usePrefetchInfiniteQuery, usePrefetchQuery, useQueries, useQuery, useQueryClient, useQueryErrorResetBoundary, useSuspenseInfiniteQuery, useSuspenseQueries, useSuspenseQuery };
|
package/build/modern/index.d.ts
CHANGED
|
@@ -18,4 +18,4 @@ import { useMutation } from "./useMutation.js";
|
|
|
18
18
|
import { mutationOptions } from "./mutationOptions.js";
|
|
19
19
|
import { useInfiniteQuery } from "./useInfiniteQuery.js";
|
|
20
20
|
export * from "@tanstack/query-core";
|
|
21
|
-
export { AnyUseBaseQueryOptions, AnyUseInfiniteQueryOptions, AnyUseMutationOptions, AnyUseQueryOptions, AnyUseSuspenseInfiniteQueryOptions, AnyUseSuspenseQueryOptions, type DefinedInitialDataInfiniteOptions, type DefinedInitialDataOptions, DefinedUseInfiniteQueryResult, DefinedUseQueryResult, HydrationBoundary, type HydrationBoundaryProps, IsRestoringProvider, type QueriesOptions, type QueriesResults, QueryClientContext, QueryClientProvider, type QueryClientProviderProps, type QueryErrorClearResetFunction, type QueryErrorIsResetFunction, QueryErrorResetBoundary, type QueryErrorResetBoundaryFunction, type QueryErrorResetBoundaryProps, type QueryErrorResetFunction, type SuspenseQueriesOptions, type SuspenseQueriesResults, type UndefinedInitialDataInfiniteOptions, type UndefinedInitialDataOptions, type UnusedSkipTokenInfiniteOptions, type UnusedSkipTokenOptions, UseBaseMutationResult, UseBaseQueryOptions, UseBaseQueryResult, UseInfiniteQueryOptions, UseInfiniteQueryResult, UseMutateAsyncFunction, UseMutateFunction, UseMutationOptions, UseMutationResult, UsePrefetchInfiniteQueryOptions, UsePrefetchQueryOptions, UseQueryOptions, UseQueryResult, UseSuspenseInfiniteQueryOptions, UseSuspenseInfiniteQueryResult, UseSuspenseQueryOptions, UseSuspenseQueryResult, infiniteQueryOptions, mutationOptions, queryOptions, useInfiniteQuery, useIsFetching, useIsMutating, useIsRestoring, useMutation, useMutationState, usePrefetchInfiniteQuery, usePrefetchQuery, useQueries, useQuery, useQueryClient, useQueryErrorResetBoundary, useSuspenseInfiniteQuery, useSuspenseQueries, useSuspenseQuery };
|
|
21
|
+
export { type AnyUseBaseQueryOptions, type AnyUseInfiniteQueryOptions, type AnyUseMutationOptions, type AnyUseQueryOptions, type AnyUseSuspenseInfiniteQueryOptions, type AnyUseSuspenseQueryOptions, type DefinedInitialDataInfiniteOptions, type DefinedInitialDataOptions, type DefinedUseInfiniteQueryResult, type DefinedUseQueryResult, HydrationBoundary, type HydrationBoundaryProps, IsRestoringProvider, type QueriesOptions, type QueriesResults, QueryClientContext, QueryClientProvider, type QueryClientProviderProps, type QueryErrorClearResetFunction, type QueryErrorIsResetFunction, QueryErrorResetBoundary, type QueryErrorResetBoundaryFunction, type QueryErrorResetBoundaryProps, type QueryErrorResetFunction, type SuspenseQueriesOptions, type SuspenseQueriesResults, type UndefinedInitialDataInfiniteOptions, type UndefinedInitialDataOptions, type UnusedSkipTokenInfiniteOptions, type UnusedSkipTokenOptions, type UseBaseMutationResult, type UseBaseQueryOptions, type UseBaseQueryResult, type UseInfiniteQueryOptions, type UseInfiniteQueryResult, type UseMutateAsyncFunction, type UseMutateFunction, type UseMutationOptions, type UseMutationResult, type UsePrefetchInfiniteQueryOptions, type UsePrefetchQueryOptions, type UseQueryOptions, type UseQueryResult, type UseSuspenseInfiniteQueryOptions, type UseSuspenseInfiniteQueryResult, type UseSuspenseQueryOptions, type UseSuspenseQueryResult, infiniteQueryOptions, mutationOptions, queryOptions, useInfiniteQuery, useIsFetching, useIsMutating, useIsRestoring, useMutation, useMutationState, usePrefetchInfiniteQuery, usePrefetchQuery, useQueries, useQuery, useQueryClient, useQueryErrorResetBoundary, useSuspenseInfiniteQuery, useSuspenseQueries, useSuspenseQuery };
|
package/build/modern/index.js
CHANGED
|
@@ -2,7 +2,6 @@ import { QueryClientContext, QueryClientProvider, useQueryClient } from "./Query
|
|
|
2
2
|
import { HydrationBoundary } from "./HydrationBoundary.js";
|
|
3
3
|
import { IsRestoringProvider, useIsRestoring } from "./IsRestoringProvider.js";
|
|
4
4
|
import { QueryErrorResetBoundary, useQueryErrorResetBoundary } from "./QueryErrorResetBoundary.js";
|
|
5
|
-
import "./types.js";
|
|
6
5
|
import { useQueries } from "./useQueries.js";
|
|
7
6
|
import { useQuery } from "./useQuery.js";
|
|
8
7
|
import { useSuspenseQuery } from "./useSuspenseQuery.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["/* istanbul ignore file */\n\n// Re-export core\nexport * from '@tanstack/query-core'\n\n// Preact Query\nexport * from './types'\nexport { useQueries } from './useQueries'\nexport type { QueriesResults, QueriesOptions } from './useQueries'\nexport { useQuery } from './useQuery'\nexport { useSuspenseQuery } from './useSuspenseQuery'\nexport { useSuspenseInfiniteQuery } from './useSuspenseInfiniteQuery'\nexport { useSuspenseQueries } from './useSuspenseQueries'\nexport type {\n SuspenseQueriesResults,\n SuspenseQueriesOptions,\n} from './useSuspenseQueries'\nexport { usePrefetchQuery } from './usePrefetchQuery'\nexport { usePrefetchInfiniteQuery } from './usePrefetchInfiniteQuery'\nexport { queryOptions } from './queryOptions'\nexport type {\n DefinedInitialDataOptions,\n UndefinedInitialDataOptions,\n UnusedSkipTokenOptions,\n} from './queryOptions'\nexport { infiniteQueryOptions } from './infiniteQueryOptions'\nexport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n UnusedSkipTokenInfiniteOptions,\n} from './infiniteQueryOptions'\nexport {\n QueryClientContext,\n QueryClientProvider,\n useQueryClient,\n} from './QueryClientProvider'\nexport type { QueryClientProviderProps } from './QueryClientProvider'\nexport type { QueryErrorResetBoundaryProps } from './QueryErrorResetBoundary'\nexport { HydrationBoundary } from './HydrationBoundary'\nexport type { HydrationBoundaryProps } from './HydrationBoundary'\nexport type {\n QueryErrorClearResetFunction,\n QueryErrorIsResetFunction,\n QueryErrorResetBoundaryFunction,\n QueryErrorResetFunction,\n} from './QueryErrorResetBoundary'\nexport {\n QueryErrorResetBoundary,\n useQueryErrorResetBoundary,\n} from './QueryErrorResetBoundary'\nexport { useIsFetching } from './useIsFetching'\nexport { useIsMutating, useMutationState } from './useMutationState'\nexport { useMutation } from './useMutation'\nexport { mutationOptions } from './mutationOptions'\nexport { useInfiniteQuery } from './useInfiniteQuery'\nexport { useIsRestoring, IsRestoringProvider } from './IsRestoringProvider'\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["/* istanbul ignore file */\n\n// Re-export core\nexport * from '@tanstack/query-core'\n\n// Preact Query\nexport type * from './types'\nexport { useQueries } from './useQueries'\nexport type { QueriesResults, QueriesOptions } from './useQueries'\nexport { useQuery } from './useQuery'\nexport { useSuspenseQuery } from './useSuspenseQuery'\nexport { useSuspenseInfiniteQuery } from './useSuspenseInfiniteQuery'\nexport { useSuspenseQueries } from './useSuspenseQueries'\nexport type {\n SuspenseQueriesResults,\n SuspenseQueriesOptions,\n} from './useSuspenseQueries'\nexport { usePrefetchQuery } from './usePrefetchQuery'\nexport { usePrefetchInfiniteQuery } from './usePrefetchInfiniteQuery'\nexport { queryOptions } from './queryOptions'\nexport type {\n DefinedInitialDataOptions,\n UndefinedInitialDataOptions,\n UnusedSkipTokenOptions,\n} from './queryOptions'\nexport { infiniteQueryOptions } from './infiniteQueryOptions'\nexport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n UnusedSkipTokenInfiniteOptions,\n} from './infiniteQueryOptions'\nexport {\n QueryClientContext,\n QueryClientProvider,\n useQueryClient,\n} from './QueryClientProvider'\nexport type { QueryClientProviderProps } from './QueryClientProvider'\nexport type { QueryErrorResetBoundaryProps } from './QueryErrorResetBoundary'\nexport { HydrationBoundary } from './HydrationBoundary'\nexport type { HydrationBoundaryProps } from './HydrationBoundary'\nexport type {\n QueryErrorClearResetFunction,\n QueryErrorIsResetFunction,\n QueryErrorResetBoundaryFunction,\n QueryErrorResetFunction,\n} from './QueryErrorResetBoundary'\nexport {\n QueryErrorResetBoundary,\n useQueryErrorResetBoundary,\n} from './QueryErrorResetBoundary'\nexport { useIsFetching } from './useIsFetching'\nexport { useIsMutating, useMutationState } from './useMutationState'\nexport { useMutation } from './useMutation'\nexport { mutationOptions } from './mutationOptions'\nexport { useInfiniteQuery } from './useInfiniteQuery'\nexport { useIsRestoring, IsRestoringProvider } from './IsRestoringProvider'\n"],"mappings":""}
|
|
@@ -33,13 +33,14 @@ function useBaseQuery(options, Observer, queryClient) {
|
|
|
33
33
|
if (process.env.NODE_ENV !== "production") {
|
|
34
34
|
if (!defaultedOptions.queryFn) console.error(`[${defaultedOptions.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`);
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
const subscribed = options.subscribed !== false;
|
|
37
|
+
defaultedOptions._optimisticResults = isRestoring ? "isRestoring" : subscribed ? "optimistic" : void 0;
|
|
37
38
|
require_suspense.ensureSuspenseTimers(defaultedOptions);
|
|
38
39
|
require_errorBoundaryUtils.ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary, query);
|
|
39
40
|
require_errorBoundaryUtils.useClearResetErrorBoundary(errorResetBoundary);
|
|
40
41
|
const [observer] = (0, preact_hooks.useState)(() => new Observer(client, defaultedOptions));
|
|
41
42
|
const result = observer.getOptimisticResult(defaultedOptions);
|
|
42
|
-
const shouldSubscribe = !isRestoring &&
|
|
43
|
+
const shouldSubscribe = !isRestoring && subscribed;
|
|
43
44
|
require_utils.useSyncExternalStore((0, preact_hooks.useCallback)((onStoreChange) => {
|
|
44
45
|
const unsubscribe = shouldSubscribe ? observer.subscribe(_tanstack_query_core.notifyManager.batchCalls(onStoreChange)) : _tanstack_query_core.noop;
|
|
45
46
|
observer.updateResult();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBaseQuery.cjs","names":["useIsRestoring","useQueryErrorResetBoundary","useQueryClient","useState","useCallback","notifyManager","noop","shouldSuspend","fetchOptimistic","getHasError"],"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import { noop, notifyManager } from '@tanstack/query-core'\nimport { useCallback, useEffect, useState } from 'preact/hooks'\n\nimport { useIsRestoring } from './IsRestoringProvider'\nimport { useQueryClient } from './QueryClientProvider'\nimport { useQueryErrorResetBoundary } from './QueryErrorResetBoundary'\nimport {\n ensurePreventErrorBoundaryRetry,\n getHasError,\n useClearResetErrorBoundary,\n} from './errorBoundaryUtils'\nimport {\n ensureSuspenseTimers,\n fetchOptimistic,\n shouldSuspend,\n} from './suspense'\nimport { useSyncExternalStore } from './utils'\nimport type { UseBaseQueryOptions } from './types'\nimport type {\n QueryClient,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\n\n/**\n * Base implementation shared by `useQuery`, `useInfiniteQuery`, `useSuspenseQuery`, and\n * `useSuspenseInfiniteQuery`.\n * @param options - The options passed to the calling hook.\n * @param Observer - The observer class from query-core (`QueryObserver` or\n * `InfiniteQueryObserver`).\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest\n * context will be used.\n * @returns The query result, tracking which properties are read unless `notifyOnChangeProps` is\n * set.\n * @throws {Error} If `options` is not an object (outside production), or the query error when it should be\n * thrown to the nearest error boundary (see `throwOnError`). While suspending, it throws a promise instead.\n */\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: UseBaseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n Observer: typeof QueryObserver,\n queryClient?: QueryClient,\n): QueryObserverResult<TData, TError> {\n if (process.env.NODE_ENV !== 'production') {\n if (typeof options !== 'object' || Array.isArray(options)) {\n throw new Error(\n 'Bad argument type. Starting with v5, only the \"Object\" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object',\n )\n }\n }\n\n const isRestoring = useIsRestoring()\n const errorResetBoundary = useQueryErrorResetBoundary()\n const client = useQueryClient(queryClient)\n const defaultedOptions = client.defaultQueryOptions(options)\n\n const query = client\n .getQueryCache()\n .get<TQueryFnData, TError, TQueryData, TQueryKey>(\n defaultedOptions.queryHash,\n )\n\n if (process.env.NODE_ENV !== 'production') {\n if (!defaultedOptions.queryFn) {\n console.error(\n `[${defaultedOptions.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`,\n )\n }\n }\n\n // Make sure results are optimistically set in fetching state before subscribing or updating options\n defaultedOptions._optimisticResults = isRestoring\n ? 'isRestoring'\n : 'optimistic'\n\n ensureSuspenseTimers(defaultedOptions)\n ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary, query)\n\n useClearResetErrorBoundary(errorResetBoundary)\n\n const [observer] = useState(\n () =>\n new Observer<TQueryFnData, TError, TData, TQueryData, TQueryKey>(\n client,\n defaultedOptions,\n ),\n )\n\n // note: this must be called before useSyncExternalStore\n const result = observer.getOptimisticResult(defaultedOptions)\n\n const shouldSubscribe = !isRestoring &&
|
|
1
|
+
{"version":3,"file":"useBaseQuery.cjs","names":["useIsRestoring","useQueryErrorResetBoundary","useQueryClient","useState","useCallback","notifyManager","noop","shouldSuspend","fetchOptimistic","getHasError"],"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import { noop, notifyManager } from '@tanstack/query-core'\nimport { useCallback, useEffect, useState } from 'preact/hooks'\n\nimport { useIsRestoring } from './IsRestoringProvider'\nimport { useQueryClient } from './QueryClientProvider'\nimport { useQueryErrorResetBoundary } from './QueryErrorResetBoundary'\nimport {\n ensurePreventErrorBoundaryRetry,\n getHasError,\n useClearResetErrorBoundary,\n} from './errorBoundaryUtils'\nimport {\n ensureSuspenseTimers,\n fetchOptimistic,\n shouldSuspend,\n} from './suspense'\nimport { useSyncExternalStore } from './utils'\nimport type { UseBaseQueryOptions } from './types'\nimport type {\n QueryClient,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\n\n/**\n * Base implementation shared by `useQuery`, `useInfiniteQuery`, `useSuspenseQuery`, and\n * `useSuspenseInfiniteQuery`.\n * @param options - The options passed to the calling hook.\n * @param Observer - The observer class from query-core (`QueryObserver` or\n * `InfiniteQueryObserver`).\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest\n * context will be used.\n * @returns The query result, tracking which properties are read unless `notifyOnChangeProps` is\n * set.\n * @throws {Error} If `options` is not an object (outside production), or the query error when it should be\n * thrown to the nearest error boundary (see `throwOnError`). While suspending, it throws a promise instead.\n */\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: UseBaseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n Observer: typeof QueryObserver,\n queryClient?: QueryClient,\n): QueryObserverResult<TData, TError> {\n if (process.env.NODE_ENV !== 'production') {\n if (typeof options !== 'object' || Array.isArray(options)) {\n throw new Error(\n 'Bad argument type. Starting with v5, only the \"Object\" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object',\n )\n }\n }\n\n const isRestoring = useIsRestoring()\n const errorResetBoundary = useQueryErrorResetBoundary()\n const client = useQueryClient(queryClient)\n const defaultedOptions = client.defaultQueryOptions(options)\n\n const query = client\n .getQueryCache()\n .get<TQueryFnData, TError, TQueryData, TQueryKey>(\n defaultedOptions.queryHash,\n )\n\n if (process.env.NODE_ENV !== 'production') {\n if (!defaultedOptions.queryFn) {\n console.error(\n `[${defaultedOptions.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`,\n )\n }\n }\n\n const subscribed = options.subscribed !== false\n\n // Make sure results are optimistically set in fetching state before subscribing or updating options\n defaultedOptions._optimisticResults = isRestoring\n ? 'isRestoring'\n : subscribed\n ? 'optimistic'\n : undefined\n\n ensureSuspenseTimers(defaultedOptions)\n ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary, query)\n\n useClearResetErrorBoundary(errorResetBoundary)\n\n const [observer] = useState(\n () =>\n new Observer<TQueryFnData, TError, TData, TQueryData, TQueryKey>(\n client,\n defaultedOptions,\n ),\n )\n\n // note: this must be called before useSyncExternalStore\n const result = observer.getOptimisticResult(defaultedOptions)\n\n const shouldSubscribe = !isRestoring && subscribed\n useSyncExternalStore(\n useCallback(\n (onStoreChange) => {\n const unsubscribe = shouldSubscribe\n ? observer.subscribe(notifyManager.batchCalls(onStoreChange))\n : noop\n\n // Update result to make sure we did not miss any query updates\n // between creating the observer and subscribing to it.\n observer.updateResult()\n\n return unsubscribe\n },\n [observer, shouldSubscribe],\n ),\n () => observer.getCurrentResult(),\n )\n\n useEffect(() => {\n observer.setOptions(defaultedOptions)\n }, [defaultedOptions, observer])\n\n // Handle suspense\n if (shouldSuspend(defaultedOptions, result)) {\n throw fetchOptimistic(defaultedOptions, observer, errorResetBoundary)\n }\n\n // Handle error boundary\n if (\n getHasError({\n result,\n errorResetBoundary,\n throwOnError: defaultedOptions.throwOnError,\n query,\n suspense: defaultedOptions.suspense,\n })\n ) {\n throw result.error\n }\n\n // Handle result property usage tracking\n return !defaultedOptions.notifyOnChangeProps\n ? observer.trackResult(result)\n : result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,aAOd,SAOA,UACA,aACoC;CACpC,IAAI,QAAQ,IAAI,aAAa,cACvB;MAAA,OAAO,YAAY,YAAY,MAAM,QAAQ,OAAO,GACtD,MAAM,IAAI,MACR,gSACF;CAAA;CAIJ,MAAM,cAAcA,4BAAAA,eAAe;CACnC,MAAM,qBAAqBC,gCAAAA,2BAA2B;CACtD,MAAM,SAASC,4BAAAA,eAAe,WAAW;CACzC,MAAM,mBAAmB,OAAO,oBAAoB,OAAO;CAE3D,MAAM,QAAQ,OACX,cAAc,CAAC,CACf,IACC,iBAAiB,SACnB;CAEF,IAAI,QAAQ,IAAI,aAAa,cACvB;MAAA,CAAC,iBAAiB,SACpB,QAAQ,MACN,IAAI,iBAAiB,UAAU,mPACjC;CAAA;CAIJ,MAAM,aAAa,QAAQ,eAAe;CAG1C,iBAAiB,qBAAqB,cAClC,gBACA,aACE,eACA,KAAA;CAEN,iBAAA,qBAAqB,gBAAgB;CACrC,2BAAA,gCAAgC,kBAAkB,oBAAoB,KAAK;CAE3E,2BAAA,2BAA2B,kBAAkB;CAE7C,MAAM,CAAC,aAAA,GAAYC,aAAAA,SAAAA,OAEf,IAAI,SACF,QACA,gBACF,CACJ;CAGA,MAAM,SAAS,SAAS,oBAAoB,gBAAgB;CAE5D,MAAM,kBAAkB,CAAC,eAAe;CACxC,cAAA,sBAAA,GACEC,aAAAA,YAAAA,EACG,kBAAkB;EACjB,MAAM,cAAc,kBAChB,SAAS,UAAUC,qBAAAA,cAAc,WAAW,aAAa,CAAC,IAC1DC,qBAAAA;EAIJ,SAAS,aAAa;EAEtB,OAAO;CACT,GACA,CAAC,UAAU,eAAe,CAC5B,SACM,SAAS,iBAAiB,CAClC;CAEA,CAAA,GAAA,aAAA,UAAA,OAAgB;EACd,SAAS,WAAW,gBAAgB;CACtC,GAAG,CAAC,kBAAkB,QAAQ,CAAC;CAG/B,IAAIC,iBAAAA,cAAc,kBAAkB,MAAM,GACxC,MAAMC,iBAAAA,gBAAgB,kBAAkB,UAAU,kBAAkB;CAItE,IACEC,2BAAAA,YAAY;EACV;EACA;EACA,cAAc,iBAAiB;EAC/B;EACA,UAAU,iBAAiB;CAC7B,CAAC,GAED,MAAM,OAAO;CAIf,OAAO,CAAC,iBAAiB,sBACrB,SAAS,YAAY,MAAM,IAC3B;AACN"}
|
|
@@ -32,13 +32,14 @@ function useBaseQuery(options, Observer, queryClient) {
|
|
|
32
32
|
if (process.env.NODE_ENV !== "production") {
|
|
33
33
|
if (!defaultedOptions.queryFn) console.error(`[${defaultedOptions.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`);
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
const subscribed = options.subscribed !== false;
|
|
36
|
+
defaultedOptions._optimisticResults = isRestoring ? "isRestoring" : subscribed ? "optimistic" : void 0;
|
|
36
37
|
ensureSuspenseTimers(defaultedOptions);
|
|
37
38
|
ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary, query);
|
|
38
39
|
useClearResetErrorBoundary(errorResetBoundary);
|
|
39
40
|
const [observer] = useState(() => new Observer(client, defaultedOptions));
|
|
40
41
|
const result = observer.getOptimisticResult(defaultedOptions);
|
|
41
|
-
const shouldSubscribe = !isRestoring &&
|
|
42
|
+
const shouldSubscribe = !isRestoring && subscribed;
|
|
42
43
|
useSyncExternalStore(useCallback((onStoreChange) => {
|
|
43
44
|
const unsubscribe = shouldSubscribe ? observer.subscribe(notifyManager.batchCalls(onStoreChange)) : noop;
|
|
44
45
|
observer.updateResult();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBaseQuery.js","names":[],"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import { noop, notifyManager } from '@tanstack/query-core'\nimport { useCallback, useEffect, useState } from 'preact/hooks'\n\nimport { useIsRestoring } from './IsRestoringProvider'\nimport { useQueryClient } from './QueryClientProvider'\nimport { useQueryErrorResetBoundary } from './QueryErrorResetBoundary'\nimport {\n ensurePreventErrorBoundaryRetry,\n getHasError,\n useClearResetErrorBoundary,\n} from './errorBoundaryUtils'\nimport {\n ensureSuspenseTimers,\n fetchOptimistic,\n shouldSuspend,\n} from './suspense'\nimport { useSyncExternalStore } from './utils'\nimport type { UseBaseQueryOptions } from './types'\nimport type {\n QueryClient,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\n\n/**\n * Base implementation shared by `useQuery`, `useInfiniteQuery`, `useSuspenseQuery`, and\n * `useSuspenseInfiniteQuery`.\n * @param options - The options passed to the calling hook.\n * @param Observer - The observer class from query-core (`QueryObserver` or\n * `InfiniteQueryObserver`).\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest\n * context will be used.\n * @returns The query result, tracking which properties are read unless `notifyOnChangeProps` is\n * set.\n * @throws {Error} If `options` is not an object (outside production), or the query error when it should be\n * thrown to the nearest error boundary (see `throwOnError`). While suspending, it throws a promise instead.\n */\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: UseBaseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n Observer: typeof QueryObserver,\n queryClient?: QueryClient,\n): QueryObserverResult<TData, TError> {\n if (process.env.NODE_ENV !== 'production') {\n if (typeof options !== 'object' || Array.isArray(options)) {\n throw new Error(\n 'Bad argument type. Starting with v5, only the \"Object\" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object',\n )\n }\n }\n\n const isRestoring = useIsRestoring()\n const errorResetBoundary = useQueryErrorResetBoundary()\n const client = useQueryClient(queryClient)\n const defaultedOptions = client.defaultQueryOptions(options)\n\n const query = client\n .getQueryCache()\n .get<TQueryFnData, TError, TQueryData, TQueryKey>(\n defaultedOptions.queryHash,\n )\n\n if (process.env.NODE_ENV !== 'production') {\n if (!defaultedOptions.queryFn) {\n console.error(\n `[${defaultedOptions.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`,\n )\n }\n }\n\n // Make sure results are optimistically set in fetching state before subscribing or updating options\n defaultedOptions._optimisticResults = isRestoring\n ? 'isRestoring'\n : 'optimistic'\n\n ensureSuspenseTimers(defaultedOptions)\n ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary, query)\n\n useClearResetErrorBoundary(errorResetBoundary)\n\n const [observer] = useState(\n () =>\n new Observer<TQueryFnData, TError, TData, TQueryData, TQueryKey>(\n client,\n defaultedOptions,\n ),\n )\n\n // note: this must be called before useSyncExternalStore\n const result = observer.getOptimisticResult(defaultedOptions)\n\n const shouldSubscribe = !isRestoring &&
|
|
1
|
+
{"version":3,"file":"useBaseQuery.js","names":[],"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import { noop, notifyManager } from '@tanstack/query-core'\nimport { useCallback, useEffect, useState } from 'preact/hooks'\n\nimport { useIsRestoring } from './IsRestoringProvider'\nimport { useQueryClient } from './QueryClientProvider'\nimport { useQueryErrorResetBoundary } from './QueryErrorResetBoundary'\nimport {\n ensurePreventErrorBoundaryRetry,\n getHasError,\n useClearResetErrorBoundary,\n} from './errorBoundaryUtils'\nimport {\n ensureSuspenseTimers,\n fetchOptimistic,\n shouldSuspend,\n} from './suspense'\nimport { useSyncExternalStore } from './utils'\nimport type { UseBaseQueryOptions } from './types'\nimport type {\n QueryClient,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\n\n/**\n * Base implementation shared by `useQuery`, `useInfiniteQuery`, `useSuspenseQuery`, and\n * `useSuspenseInfiniteQuery`.\n * @param options - The options passed to the calling hook.\n * @param Observer - The observer class from query-core (`QueryObserver` or\n * `InfiniteQueryObserver`).\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest\n * context will be used.\n * @returns The query result, tracking which properties are read unless `notifyOnChangeProps` is\n * set.\n * @throws {Error} If `options` is not an object (outside production), or the query error when it should be\n * thrown to the nearest error boundary (see `throwOnError`). While suspending, it throws a promise instead.\n */\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: UseBaseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n Observer: typeof QueryObserver,\n queryClient?: QueryClient,\n): QueryObserverResult<TData, TError> {\n if (process.env.NODE_ENV !== 'production') {\n if (typeof options !== 'object' || Array.isArray(options)) {\n throw new Error(\n 'Bad argument type. Starting with v5, only the \"Object\" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object',\n )\n }\n }\n\n const isRestoring = useIsRestoring()\n const errorResetBoundary = useQueryErrorResetBoundary()\n const client = useQueryClient(queryClient)\n const defaultedOptions = client.defaultQueryOptions(options)\n\n const query = client\n .getQueryCache()\n .get<TQueryFnData, TError, TQueryData, TQueryKey>(\n defaultedOptions.queryHash,\n )\n\n if (process.env.NODE_ENV !== 'production') {\n if (!defaultedOptions.queryFn) {\n console.error(\n `[${defaultedOptions.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`,\n )\n }\n }\n\n const subscribed = options.subscribed !== false\n\n // Make sure results are optimistically set in fetching state before subscribing or updating options\n defaultedOptions._optimisticResults = isRestoring\n ? 'isRestoring'\n : subscribed\n ? 'optimistic'\n : undefined\n\n ensureSuspenseTimers(defaultedOptions)\n ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary, query)\n\n useClearResetErrorBoundary(errorResetBoundary)\n\n const [observer] = useState(\n () =>\n new Observer<TQueryFnData, TError, TData, TQueryData, TQueryKey>(\n client,\n defaultedOptions,\n ),\n )\n\n // note: this must be called before useSyncExternalStore\n const result = observer.getOptimisticResult(defaultedOptions)\n\n const shouldSubscribe = !isRestoring && subscribed\n useSyncExternalStore(\n useCallback(\n (onStoreChange) => {\n const unsubscribe = shouldSubscribe\n ? observer.subscribe(notifyManager.batchCalls(onStoreChange))\n : noop\n\n // Update result to make sure we did not miss any query updates\n // between creating the observer and subscribing to it.\n observer.updateResult()\n\n return unsubscribe\n },\n [observer, shouldSubscribe],\n ),\n () => observer.getCurrentResult(),\n )\n\n useEffect(() => {\n observer.setOptions(defaultedOptions)\n }, [defaultedOptions, observer])\n\n // Handle suspense\n if (shouldSuspend(defaultedOptions, result)) {\n throw fetchOptimistic(defaultedOptions, observer, errorResetBoundary)\n }\n\n // Handle error boundary\n if (\n getHasError({\n result,\n errorResetBoundary,\n throwOnError: defaultedOptions.throwOnError,\n query,\n suspense: defaultedOptions.suspense,\n })\n ) {\n throw result.error\n }\n\n // Handle result property usage tracking\n return !defaultedOptions.notifyOnChangeProps\n ? observer.trackResult(result)\n : result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,aAOd,SAOA,UACA,aACoC;CACpC,IAAI,QAAQ,IAAI,aAAa,cACvB;MAAA,OAAO,YAAY,YAAY,MAAM,QAAQ,OAAO,GACtD,MAAM,IAAI,MACR,gSACF;CAAA;CAIJ,MAAM,cAAc,eAAe;CACnC,MAAM,qBAAqB,2BAA2B;CACtD,MAAM,SAAS,eAAe,WAAW;CACzC,MAAM,mBAAmB,OAAO,oBAAoB,OAAO;CAE3D,MAAM,QAAQ,OACX,cAAc,CAAC,CACf,IACC,iBAAiB,SACnB;CAEF,IAAI,QAAQ,IAAI,aAAa,cACvB;MAAA,CAAC,iBAAiB,SACpB,QAAQ,MACN,IAAI,iBAAiB,UAAU,mPACjC;CAAA;CAIJ,MAAM,aAAa,QAAQ,eAAe;CAG1C,iBAAiB,qBAAqB,cAClC,gBACA,aACE,eACA,KAAA;CAEN,qBAAqB,gBAAgB;CACrC,gCAAgC,kBAAkB,oBAAoB,KAAK;CAE3E,2BAA2B,kBAAkB;CAE7C,MAAM,CAAC,YAAY,eAEf,IAAI,SACF,QACA,gBACF,CACJ;CAGA,MAAM,SAAS,SAAS,oBAAoB,gBAAgB;CAE5D,MAAM,kBAAkB,CAAC,eAAe;CACxC,qBACE,aACG,kBAAkB;EACjB,MAAM,cAAc,kBAChB,SAAS,UAAU,cAAc,WAAW,aAAa,CAAC,IAC1D;EAIJ,SAAS,aAAa;EAEtB,OAAO;CACT,GACA,CAAC,UAAU,eAAe,CAC5B,SACM,SAAS,iBAAiB,CAClC;CAEA,gBAAgB;EACd,SAAS,WAAW,gBAAgB;CACtC,GAAG,CAAC,kBAAkB,QAAQ,CAAC;CAG/B,IAAI,cAAc,kBAAkB,MAAM,GACxC,MAAM,gBAAgB,kBAAkB,UAAU,kBAAkB;CAItE,IACE,YAAY;EACV;EACA;EACA,cAAc,iBAAiB;EAC/B;EACA,UAAU,iBAAiB;CAC7B,CAAC,GAED,MAAM,OAAO;CAIf,OAAO,CAAC,iBAAiB,sBACrB,SAAS,YAAY,MAAM,IAC3B;AACN"}
|
|
@@ -31,14 +31,27 @@ function useIsMutating(filters, queryClient) {
|
|
|
31
31
|
} }, client).length;
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* @
|
|
38
|
-
* @returns The selected value of every matching mutation.
|
|
34
|
+
* Creates snapshot getters that share equal selected results across renders.
|
|
35
|
+
* A new getter is created on each render. Each getter caches its snapshot until the matching mutations
|
|
36
|
+
* or their states change.
|
|
37
|
+
* @returns A factory for snapshot getters with a shared result cache.
|
|
39
38
|
*/
|
|
40
|
-
function
|
|
41
|
-
|
|
39
|
+
function createSnapshotFactory() {
|
|
40
|
+
let previousResult;
|
|
41
|
+
return (mutationCache, options) => {
|
|
42
|
+
let inputs = [];
|
|
43
|
+
let snapshot;
|
|
44
|
+
return () => {
|
|
45
|
+
const mutations = mutationCache.findAll(options.filters);
|
|
46
|
+
const nextInputs = mutations.flatMap((mutation) => [mutation, mutation.state]);
|
|
47
|
+
if (!snapshot || nextInputs.length !== inputs.length || nextInputs.some((input, index) => !Object.is(input, inputs[index]))) {
|
|
48
|
+
inputs = nextInputs;
|
|
49
|
+
snapshot = (0, _tanstack_query_core.replaceEqualDeep)(previousResult, mutations.map((mutation) => options.select ? options.select(mutation) : mutation.state));
|
|
50
|
+
previousResult = snapshot;
|
|
51
|
+
}
|
|
52
|
+
return snapshot;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
42
55
|
}
|
|
43
56
|
/**
|
|
44
57
|
* `useMutationState` is a hook that gives you access to all mutations in the `MutationCache`. You can pass
|
|
@@ -111,19 +124,9 @@ function getResult(mutationCache, options) {
|
|
|
111
124
|
*/
|
|
112
125
|
function useMutationState(options = {}, queryClient) {
|
|
113
126
|
const mutationCache = require_QueryClientProvider.useQueryClient(queryClient).getMutationCache();
|
|
114
|
-
const
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
(0, preact_hooks.useEffect)(() => {
|
|
118
|
-
optionsRef.current = options;
|
|
119
|
-
});
|
|
120
|
-
return require_utils.useSyncExternalStore((0, preact_hooks.useCallback)((onStoreChange) => mutationCache.subscribe(() => {
|
|
121
|
-
const nextResult = (0, _tanstack_query_core.replaceEqualDeep)(resultRef.current, getResult(mutationCache, optionsRef.current));
|
|
122
|
-
if (resultRef.current !== nextResult) {
|
|
123
|
-
resultRef.current = nextResult;
|
|
124
|
-
_tanstack_query_core.notifyManager.schedule(onStoreChange);
|
|
125
|
-
}
|
|
126
|
-
}), [mutationCache]), () => resultRef.current);
|
|
127
|
+
const [createSnapshot] = (0, preact_hooks.useState)(() => createSnapshotFactory());
|
|
128
|
+
const getSnapshot = createSnapshot(mutationCache, options);
|
|
129
|
+
return require_utils.useSyncExternalStore((0, preact_hooks.useCallback)((onStoreChange) => mutationCache.subscribe(_tanstack_query_core.notifyManager.batchCalls(onStoreChange)), [mutationCache]), getSnapshot);
|
|
127
130
|
}
|
|
128
131
|
//#endregion
|
|
129
132
|
exports.useIsMutating = useIsMutating;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMutationState.cjs","names":["useQueryClient","
|
|
1
|
+
{"version":3,"file":"useMutationState.cjs","names":["useQueryClient","replaceEqualDeep","useState","useSyncExternalStore","useCallback","notifyManager"],"sources":["../../src/useMutationState.ts"],"sourcesContent":["import { useCallback, useState } from 'preact/hooks'\n\nimport { notifyManager, replaceEqualDeep } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\nimport { useSyncExternalStore } from './utils'\nimport type {\n Mutation,\n MutationCache,\n MutationFilters,\n MutationState,\n QueryClient,\n} from '@tanstack/query-core'\n\n/**\n * The `useIsMutating` hook returns the `number` of mutations that your application currently has `pending`\n * (useful for app-wide loading indicators).\n * @param filters - The {@link MutationFilters} to narrow down the matched mutations.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns Will be the `number` of the mutations that your application currently has `pending`.\n * @example\n * ```tsx\n * import { useIsMutating } from '@tanstack/preact-query'\n *\n * function PostsMutatingIndicator() {\n * // How many mutations matching the posts prefix are in progress?\n * const isMutatingPosts = useIsMutating({ mutationKey: ['posts'] })\n *\n * return isMutatingPosts ? <span>Saving posts...</span> : null\n * }\n * ```\n */\nexport function useIsMutating(\n filters?: MutationFilters,\n queryClient?: QueryClient,\n): number {\n const client = useQueryClient(queryClient)\n return useMutationState(\n { filters: { ...filters, status: 'pending' } },\n client,\n ).length\n}\n\ntype MutationTypeFromResult<TResult> = [TResult] extends [\n MutationState<\n infer TData,\n infer TError,\n infer TVariables,\n infer TOnMutateResult\n >,\n]\n ? Mutation<TData, TError, TVariables, TOnMutateResult>\n : Mutation\n\ntype MutationStateOptions<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n> = {\n filters?: MutationFilters\n select?: (mutation: TMutation) => TResult\n}\n\n/**\n * Creates snapshot getters that share equal selected results across renders.\n * A new getter is created on each render. Each getter caches its snapshot until the matching mutations\n * or their states change.\n * @returns A factory for snapshot getters with a shared result cache.\n */\nfunction createSnapshotFactory<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n>() {\n let previousResult: Array<TResult> | undefined\n\n return (\n mutationCache: MutationCache,\n options: MutationStateOptions<TResult, TMutation>,\n ) => {\n let inputs: Array<unknown> = []\n let snapshot: Array<TResult> | undefined\n\n return (): Array<TResult> => {\n const mutations = mutationCache.findAll(options.filters)\n const nextInputs = mutations.flatMap((mutation) => [\n mutation,\n mutation.state,\n ])\n\n if (\n !snapshot ||\n nextInputs.length !== inputs.length ||\n nextInputs.some((input, index) => !Object.is(input, inputs[index]))\n ) {\n inputs = nextInputs\n snapshot = replaceEqualDeep(\n previousResult,\n mutations.map(\n (mutation): TResult =>\n (options.select\n ? options.select(mutation as TMutation)\n : mutation.state) as TResult,\n ),\n )\n previousResult = snapshot\n }\n\n return snapshot\n }\n }\n}\n\n/**\n * `useMutationState` is a hook that gives you access to all mutations in the `MutationCache`. You can pass\n * `filters` ({@link MutationFilters}) to narrow down your mutations, and `select` to transform the mutation\n * state.\n * @param options - The `filters` to narrow down matched mutations, and an optional `select` to transform the\n * mutation state.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns Will be an Array of whatever `select` returns for each matching mutation.\n * @example\n * Get all variables of all running mutations:\n * ```tsx\n * import { useMutationState } from '@tanstack/preact-query'\n *\n * function PendingPosts() {\n * const pendingVariables = useMutationState({\n * filters: { status: 'pending' },\n * select: (mutation) => mutation.state.variables,\n * })\n *\n * return <>{pendingVariables.length} posts saving...</>\n * }\n * ```\n * @example\n * Get all data for specific mutations via the `mutationKey`:\n * ```tsx\n * import { useMutation, useMutationState } from '@tanstack/preact-query'\n *\n * const mutationKey = ['posts']\n *\n * function Posts() {\n * // Some mutation that we want to get the state for\n * const mutation = useMutation({\n * mutationKey,\n * mutationFn: createPosts,\n * })\n *\n * const savedPosts = useMutationState({\n * // this mutation key needs to match the mutation key of the given mutation (see above)\n * filters: { mutationKey, status: 'success' },\n * select: (mutation) => mutation.state.data,\n * })\n *\n * return (\n * <button onClick={() => mutation.mutate(['New Post'])}>\n * Create post ({savedPosts.length} saved so far)\n * </button>\n * )\n * }\n * ```\n * @example\n * Access the latest successful mutation data via the `mutationKey`. Each invocation of `mutate` adds a new\n * entry to the mutation cache for `gcTime` milliseconds — with the `status: 'success'` filter below, check the\n * last item that `useMutationState` returns to get the latest successful invocation:\n * ```tsx\n * import { useMutationState } from '@tanstack/preact-query'\n *\n * function LatestPost() {\n * const savedPosts = useMutationState({\n * filters: { mutationKey: ['posts'], status: 'success' },\n * select: (mutation) => mutation.state.data,\n * })\n *\n * const latestSavedPost = savedPosts[savedPosts.length - 1]\n *\n * return <>{latestSavedPost ? 'Saved' : 'Nothing saved yet'}</>\n * }\n * ```\n */\nexport function useMutationState<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n>(\n options: MutationStateOptions<TResult, TMutation> = {},\n queryClient?: QueryClient,\n): Array<TResult> {\n const mutationCache = useQueryClient(queryClient).getMutationCache()\n const [createSnapshot] = useState(() =>\n createSnapshotFactory<TResult, TMutation>(),\n )\n const getSnapshot = createSnapshot(mutationCache, options)\n\n return useSyncExternalStore(\n useCallback(\n (onStoreChange) =>\n mutationCache.subscribe(notifyManager.batchCalls(onStoreChange)),\n [mutationCache],\n ),\n getSnapshot,\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,SAAgB,cACd,SACA,aACQ;CACR,MAAM,SAASA,4BAAAA,eAAe,WAAW;CACzC,OAAO,iBACL,EAAE,SAAS;EAAE,GAAG;EAAS,QAAQ;CAAU,EAAE,GAC7C,MACF,CAAC,CAAC;AACJ;;;;;;;AA4BA,SAAS,wBAIL;CACF,IAAI;CAEJ,QACE,eACA,YACG;EACH,IAAI,SAAyB,CAAC;EAC9B,IAAI;EAEJ,aAA6B;GAC3B,MAAM,YAAY,cAAc,QAAQ,QAAQ,OAAO;GACvD,MAAM,aAAa,UAAU,SAAS,aAAa,CACjD,UACA,SAAS,KACX,CAAC;GAED,IACE,CAAC,YACD,WAAW,WAAW,OAAO,UAC7B,WAAW,MAAM,OAAO,UAAU,CAAC,OAAO,GAAG,OAAO,OAAO,MAAM,CAAC,GAClE;IACA,SAAS;IACT,YAAA,GAAWC,qBAAAA,iBAAAA,CACT,gBACA,UAAU,KACP,aACE,QAAQ,SACL,QAAQ,OAAO,QAAqB,IACpC,SAAS,KACjB,CACF;IACA,iBAAiB;GACnB;GAEA,OAAO;EACT;CACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuEA,SAAgB,iBAKd,UAAoD,CAAC,GACrD,aACgB;CAChB,MAAM,gBAAgBD,4BAAAA,eAAe,WAAW,CAAC,CAAC,iBAAiB;CACnE,MAAM,CAAC,mBAAA,GAAkBE,aAAAA,SAAAA,OACvB,sBAA0C,CAC5C;CACA,MAAM,cAAc,eAAe,eAAe,OAAO;CAEzD,OAAOC,cAAAA,sBAAAA,GACLC,aAAAA,YAAAA,EACG,kBACC,cAAc,UAAUC,qBAAAA,cAAc,WAAW,aAAa,CAAC,GACjE,CAAC,aAAa,CAChB,GACA,WACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMutationState.d.cts","names":[],"sources":["../../src/useMutationState.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;wBAgCgB,cACd,UAAU,iBACV,cAAc;KASX,uBAAuB,YAAY,kBACtC,oBACQ,aACA,cACA,kBACA,oBAGN,SAAS,OAAO,QAAQ,YAAY,mBACpC;KAEC,qBACH,UAAU,eACV,kBAAkB,+BAChB,uBAAuB;EAEzB,UAAU;EACV,UAAU,UAAU,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"useMutationState.d.cts","names":[],"sources":["../../src/useMutationState.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;wBAgCgB,cACd,UAAU,iBACV,cAAc;KASX,uBAAuB,YAAY,kBACtC,oBACQ,aACA,cACA,kBACA,oBAGN,SAAS,OAAO,QAAQ,YAAY,mBACpC;KAEC,qBACH,UAAU,eACV,kBAAkB,+BAChB,uBAAuB;EAEzB,UAAU;EACV,UAAU,UAAU,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA0HpB,iBACd,UAAU,eACV,kBAAkB,+BAChB,uBAAuB,UAEzB,UAAS,qBAAqB,SAAS,YACvC,cAAc,cACb,MAAM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMutationState.d.ts","names":[],"sources":["../../src/useMutationState.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;wBAgCgB,cACd,UAAU,iBACV,cAAc;KASX,uBAAuB,YAAY,kBACtC,oBACQ,aACA,cACA,kBACA,oBAGN,SAAS,OAAO,QAAQ,YAAY,mBACpC;KAEC,qBACH,UAAU,eACV,kBAAkB,+BAChB,uBAAuB;EAEzB,UAAU;EACV,UAAU,UAAU,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"useMutationState.d.ts","names":[],"sources":["../../src/useMutationState.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;wBAgCgB,cACd,UAAU,iBACV,cAAc;KASX,uBAAuB,YAAY,kBACtC,oBACQ,aACA,cACA,kBACA,oBAGN,SAAS,OAAO,QAAQ,YAAY,mBACpC;KAEC,qBACH,UAAU,eACV,kBAAkB,+BAChB,uBAAuB;EAEzB,UAAU;EACV,UAAU,UAAU,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA0HpB,iBACd,UAAU,eACV,kBAAkB,+BAChB,uBAAuB,UAEzB,UAAS,qBAAqB,SAAS,YACvC,cAAc,cACb,MAAM"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useQueryClient } from "./QueryClientProvider.js";
|
|
2
2
|
import { useSyncExternalStore } from "./utils.js";
|
|
3
3
|
import { notifyManager, replaceEqualDeep } from "@tanstack/query-core";
|
|
4
|
-
import { useCallback,
|
|
4
|
+
import { useCallback, useState } from "preact/hooks";
|
|
5
5
|
//#region src/useMutationState.ts
|
|
6
6
|
/**
|
|
7
7
|
* The `useIsMutating` hook returns the `number` of mutations that your application currently has `pending`
|
|
@@ -30,14 +30,27 @@ function useIsMutating(filters, queryClient) {
|
|
|
30
30
|
} }, client).length;
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* @
|
|
37
|
-
* @returns The selected value of every matching mutation.
|
|
33
|
+
* Creates snapshot getters that share equal selected results across renders.
|
|
34
|
+
* A new getter is created on each render. Each getter caches its snapshot until the matching mutations
|
|
35
|
+
* or their states change.
|
|
36
|
+
* @returns A factory for snapshot getters with a shared result cache.
|
|
38
37
|
*/
|
|
39
|
-
function
|
|
40
|
-
|
|
38
|
+
function createSnapshotFactory() {
|
|
39
|
+
let previousResult;
|
|
40
|
+
return (mutationCache, options) => {
|
|
41
|
+
let inputs = [];
|
|
42
|
+
let snapshot;
|
|
43
|
+
return () => {
|
|
44
|
+
const mutations = mutationCache.findAll(options.filters);
|
|
45
|
+
const nextInputs = mutations.flatMap((mutation) => [mutation, mutation.state]);
|
|
46
|
+
if (!snapshot || nextInputs.length !== inputs.length || nextInputs.some((input, index) => !Object.is(input, inputs[index]))) {
|
|
47
|
+
inputs = nextInputs;
|
|
48
|
+
snapshot = replaceEqualDeep(previousResult, mutations.map((mutation) => options.select ? options.select(mutation) : mutation.state));
|
|
49
|
+
previousResult = snapshot;
|
|
50
|
+
}
|
|
51
|
+
return snapshot;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
41
54
|
}
|
|
42
55
|
/**
|
|
43
56
|
* `useMutationState` is a hook that gives you access to all mutations in the `MutationCache`. You can pass
|
|
@@ -110,19 +123,9 @@ function getResult(mutationCache, options) {
|
|
|
110
123
|
*/
|
|
111
124
|
function useMutationState(options = {}, queryClient) {
|
|
112
125
|
const mutationCache = useQueryClient(queryClient).getMutationCache();
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
useEffect(() => {
|
|
117
|
-
optionsRef.current = options;
|
|
118
|
-
});
|
|
119
|
-
return useSyncExternalStore(useCallback((onStoreChange) => mutationCache.subscribe(() => {
|
|
120
|
-
const nextResult = replaceEqualDeep(resultRef.current, getResult(mutationCache, optionsRef.current));
|
|
121
|
-
if (resultRef.current !== nextResult) {
|
|
122
|
-
resultRef.current = nextResult;
|
|
123
|
-
notifyManager.schedule(onStoreChange);
|
|
124
|
-
}
|
|
125
|
-
}), [mutationCache]), () => resultRef.current);
|
|
126
|
+
const [createSnapshot] = useState(() => createSnapshotFactory());
|
|
127
|
+
const getSnapshot = createSnapshot(mutationCache, options);
|
|
128
|
+
return useSyncExternalStore(useCallback((onStoreChange) => mutationCache.subscribe(notifyManager.batchCalls(onStoreChange)), [mutationCache]), getSnapshot);
|
|
126
129
|
}
|
|
127
130
|
//#endregion
|
|
128
131
|
export { useIsMutating, useMutationState };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMutationState.js","names":[],"sources":["../../src/useMutationState.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useMutationState.js","names":[],"sources":["../../src/useMutationState.ts"],"sourcesContent":["import { useCallback, useState } from 'preact/hooks'\n\nimport { notifyManager, replaceEqualDeep } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\nimport { useSyncExternalStore } from './utils'\nimport type {\n Mutation,\n MutationCache,\n MutationFilters,\n MutationState,\n QueryClient,\n} from '@tanstack/query-core'\n\n/**\n * The `useIsMutating` hook returns the `number` of mutations that your application currently has `pending`\n * (useful for app-wide loading indicators).\n * @param filters - The {@link MutationFilters} to narrow down the matched mutations.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns Will be the `number` of the mutations that your application currently has `pending`.\n * @example\n * ```tsx\n * import { useIsMutating } from '@tanstack/preact-query'\n *\n * function PostsMutatingIndicator() {\n * // How many mutations matching the posts prefix are in progress?\n * const isMutatingPosts = useIsMutating({ mutationKey: ['posts'] })\n *\n * return isMutatingPosts ? <span>Saving posts...</span> : null\n * }\n * ```\n */\nexport function useIsMutating(\n filters?: MutationFilters,\n queryClient?: QueryClient,\n): number {\n const client = useQueryClient(queryClient)\n return useMutationState(\n { filters: { ...filters, status: 'pending' } },\n client,\n ).length\n}\n\ntype MutationTypeFromResult<TResult> = [TResult] extends [\n MutationState<\n infer TData,\n infer TError,\n infer TVariables,\n infer TOnMutateResult\n >,\n]\n ? Mutation<TData, TError, TVariables, TOnMutateResult>\n : Mutation\n\ntype MutationStateOptions<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n> = {\n filters?: MutationFilters\n select?: (mutation: TMutation) => TResult\n}\n\n/**\n * Creates snapshot getters that share equal selected results across renders.\n * A new getter is created on each render. Each getter caches its snapshot until the matching mutations\n * or their states change.\n * @returns A factory for snapshot getters with a shared result cache.\n */\nfunction createSnapshotFactory<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n>() {\n let previousResult: Array<TResult> | undefined\n\n return (\n mutationCache: MutationCache,\n options: MutationStateOptions<TResult, TMutation>,\n ) => {\n let inputs: Array<unknown> = []\n let snapshot: Array<TResult> | undefined\n\n return (): Array<TResult> => {\n const mutations = mutationCache.findAll(options.filters)\n const nextInputs = mutations.flatMap((mutation) => [\n mutation,\n mutation.state,\n ])\n\n if (\n !snapshot ||\n nextInputs.length !== inputs.length ||\n nextInputs.some((input, index) => !Object.is(input, inputs[index]))\n ) {\n inputs = nextInputs\n snapshot = replaceEqualDeep(\n previousResult,\n mutations.map(\n (mutation): TResult =>\n (options.select\n ? options.select(mutation as TMutation)\n : mutation.state) as TResult,\n ),\n )\n previousResult = snapshot\n }\n\n return snapshot\n }\n }\n}\n\n/**\n * `useMutationState` is a hook that gives you access to all mutations in the `MutationCache`. You can pass\n * `filters` ({@link MutationFilters}) to narrow down your mutations, and `select` to transform the mutation\n * state.\n * @param options - The `filters` to narrow down matched mutations, and an optional `select` to transform the\n * mutation state.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns Will be an Array of whatever `select` returns for each matching mutation.\n * @example\n * Get all variables of all running mutations:\n * ```tsx\n * import { useMutationState } from '@tanstack/preact-query'\n *\n * function PendingPosts() {\n * const pendingVariables = useMutationState({\n * filters: { status: 'pending' },\n * select: (mutation) => mutation.state.variables,\n * })\n *\n * return <>{pendingVariables.length} posts saving...</>\n * }\n * ```\n * @example\n * Get all data for specific mutations via the `mutationKey`:\n * ```tsx\n * import { useMutation, useMutationState } from '@tanstack/preact-query'\n *\n * const mutationKey = ['posts']\n *\n * function Posts() {\n * // Some mutation that we want to get the state for\n * const mutation = useMutation({\n * mutationKey,\n * mutationFn: createPosts,\n * })\n *\n * const savedPosts = useMutationState({\n * // this mutation key needs to match the mutation key of the given mutation (see above)\n * filters: { mutationKey, status: 'success' },\n * select: (mutation) => mutation.state.data,\n * })\n *\n * return (\n * <button onClick={() => mutation.mutate(['New Post'])}>\n * Create post ({savedPosts.length} saved so far)\n * </button>\n * )\n * }\n * ```\n * @example\n * Access the latest successful mutation data via the `mutationKey`. Each invocation of `mutate` adds a new\n * entry to the mutation cache for `gcTime` milliseconds — with the `status: 'success'` filter below, check the\n * last item that `useMutationState` returns to get the latest successful invocation:\n * ```tsx\n * import { useMutationState } from '@tanstack/preact-query'\n *\n * function LatestPost() {\n * const savedPosts = useMutationState({\n * filters: { mutationKey: ['posts'], status: 'success' },\n * select: (mutation) => mutation.state.data,\n * })\n *\n * const latestSavedPost = savedPosts[savedPosts.length - 1]\n *\n * return <>{latestSavedPost ? 'Saved' : 'Nothing saved yet'}</>\n * }\n * ```\n */\nexport function useMutationState<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n>(\n options: MutationStateOptions<TResult, TMutation> = {},\n queryClient?: QueryClient,\n): Array<TResult> {\n const mutationCache = useQueryClient(queryClient).getMutationCache()\n const [createSnapshot] = useState(() =>\n createSnapshotFactory<TResult, TMutation>(),\n )\n const getSnapshot = createSnapshot(mutationCache, options)\n\n return useSyncExternalStore(\n useCallback(\n (onStoreChange) =>\n mutationCache.subscribe(notifyManager.batchCalls(onStoreChange)),\n [mutationCache],\n ),\n getSnapshot,\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAgCA,SAAgB,cACd,SACA,aACQ;CACR,MAAM,SAAS,eAAe,WAAW;CACzC,OAAO,iBACL,EAAE,SAAS;EAAE,GAAG;EAAS,QAAQ;CAAU,EAAE,GAC7C,MACF,CAAC,CAAC;AACJ;;;;;;;AA4BA,SAAS,wBAIL;CACF,IAAI;CAEJ,QACE,eACA,YACG;EACH,IAAI,SAAyB,CAAC;EAC9B,IAAI;EAEJ,aAA6B;GAC3B,MAAM,YAAY,cAAc,QAAQ,QAAQ,OAAO;GACvD,MAAM,aAAa,UAAU,SAAS,aAAa,CACjD,UACA,SAAS,KACX,CAAC;GAED,IACE,CAAC,YACD,WAAW,WAAW,OAAO,UAC7B,WAAW,MAAM,OAAO,UAAU,CAAC,OAAO,GAAG,OAAO,OAAO,MAAM,CAAC,GAClE;IACA,SAAS;IACT,WAAW,iBACT,gBACA,UAAU,KACP,aACE,QAAQ,SACL,QAAQ,OAAO,QAAqB,IACpC,SAAS,KACjB,CACF;IACA,iBAAiB;GACnB;GAEA,OAAO;EACT;CACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuEA,SAAgB,iBAKd,UAAoD,CAAC,GACrD,aACgB;CAChB,MAAM,gBAAgB,eAAe,WAAW,CAAC,CAAC,iBAAiB;CACnE,MAAM,CAAC,kBAAkB,eACvB,sBAA0C,CAC5C;CACA,MAAM,cAAc,eAAe,eAAe,OAAO;CAEzD,OAAO,qBACL,aACG,kBACC,cAAc,UAAU,cAAc,WAAW,aAAa,CAAC,GACjE,CAAC,aAAa,CAChB,GACA,WACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/preact-query",
|
|
3
|
-
"version": "5.104.
|
|
3
|
+
"version": "5.104.5",
|
|
4
4
|
"description": "Hooks for managing, caching and syncing asynchronous and remote data in preact",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
"!build/codemods/**/__tests__"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@tanstack/query-core": "5.104.
|
|
46
|
+
"@tanstack/query-core": "5.104.5"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@preact/preset-vite": "^2.10.6",
|
|
50
|
-
"@tanstack/query-persist-client-core": "5.104.
|
|
50
|
+
"@tanstack/query-persist-client-core": "5.104.5",
|
|
51
51
|
"@tanstack/query-test-utils": "0.0.0",
|
|
52
52
|
"@testing-library/preact": "^3.2.4",
|
|
53
53
|
"preact": "^11.0.1",
|
|
@@ -36,8 +36,12 @@ export const ensurePreventErrorBoundaryRetry = <
|
|
|
36
36
|
query: Query<TQueryFnData, TError, TQueryData, TQueryKey> | undefined,
|
|
37
37
|
) => {
|
|
38
38
|
const throwOnError =
|
|
39
|
-
query?.state.
|
|
40
|
-
|
|
39
|
+
query?.state.status === 'error' &&
|
|
40
|
+
typeof options.throwOnError === 'function'
|
|
41
|
+
? shouldThrowError(options.throwOnError, [
|
|
42
|
+
query.state.error as TError,
|
|
43
|
+
query,
|
|
44
|
+
])
|
|
41
45
|
: options.throwOnError
|
|
42
46
|
|
|
43
47
|
if (options.suspense || throwOnError) {
|
package/src/index.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
export * from '@tanstack/query-core'
|
|
5
5
|
|
|
6
6
|
// Preact Query
|
|
7
|
-
export * from './types'
|
|
7
|
+
export type * from './types'
|
|
8
8
|
export { useQueries } from './useQueries'
|
|
9
9
|
export type { QueriesResults, QueriesOptions } from './useQueries'
|
|
10
10
|
export { useQuery } from './useQuery'
|
package/src/useBaseQuery.ts
CHANGED
|
@@ -80,10 +80,14 @@ export function useBaseQuery<
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
const subscribed = options.subscribed !== false
|
|
84
|
+
|
|
83
85
|
// Make sure results are optimistically set in fetching state before subscribing or updating options
|
|
84
86
|
defaultedOptions._optimisticResults = isRestoring
|
|
85
87
|
? 'isRestoring'
|
|
86
|
-
:
|
|
88
|
+
: subscribed
|
|
89
|
+
? 'optimistic'
|
|
90
|
+
: undefined
|
|
87
91
|
|
|
88
92
|
ensureSuspenseTimers(defaultedOptions)
|
|
89
93
|
ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary, query)
|
|
@@ -101,7 +105,7 @@ export function useBaseQuery<
|
|
|
101
105
|
// note: this must be called before useSyncExternalStore
|
|
102
106
|
const result = observer.getOptimisticResult(defaultedOptions)
|
|
103
107
|
|
|
104
|
-
const shouldSubscribe = !isRestoring &&
|
|
108
|
+
const shouldSubscribe = !isRestoring && subscribed
|
|
105
109
|
useSyncExternalStore(
|
|
106
110
|
useCallback(
|
|
107
111
|
(onStoreChange) => {
|