@tanstack/solid-query
Advanced tools
Comparing version 5.24.1 to 5.24.2
import { notifyManager, QueryClient as QueryClient$1, MutationObserver, replaceEqualDeep, QueriesObserver, hydrate, QueryObserver, InfiniteQueryObserver } from '@tanstack/query-core'; | ||
export * from '@tanstack/query-core'; | ||
import { batch, createContext, useContext, createRenderEffect, onCleanup, createMemo, createSignal, createComputed, on, createEffect, mergeProps, createResource, onMount, untrack } from 'solid-js'; | ||
import { batch, createContext, useContext, createRenderEffect, onCleanup, createMemo, createSignal, createComputed, on, createEffect, mergeProps, createResource, onMount } from 'solid-js'; | ||
import { createComponent, isServer } from 'solid-js/web'; | ||
@@ -47,2 +47,4 @@ import { createStore, unwrap, reconcile } from 'solid-js/store'; | ||
} | ||
function noop() { | ||
} | ||
var IsRestoringContext = createContext(() => false); | ||
@@ -89,19 +91,15 @@ var useIsRestoring = () => useContext(IsRestoringContext); | ||
const isRestoring = useIsRestoring(); | ||
const defaultedOptions = createMemo( | ||
() => mergeProps(client()?.defaultQueryOptions(options()) || {}, { | ||
get _optimisticResults() { | ||
return isRestoring() ? "isRestoring" : "optimistic"; | ||
}, | ||
structuralSharing: false, | ||
...isServer && { retry: false, throwOnError: true } | ||
}) | ||
); | ||
const defaultedOptions = createMemo(() => { | ||
const defaultOptions = client().defaultQueryOptions(options()); | ||
defaultOptions._optimisticResults = isRestoring() ? "isRestoring" : "optimistic"; | ||
defaultOptions.structuralSharing = false; | ||
if (isServer) { | ||
defaultOptions.retry = false; | ||
defaultOptions.throwOnError = true; | ||
} | ||
return defaultOptions; | ||
}); | ||
const [observer, setObserver] = createSignal( | ||
new Observer(client(), untrack(defaultedOptions)) | ||
new Observer(client(), defaultedOptions()) | ||
); | ||
createComputed( | ||
on(client, (c) => setObserver(new Observer(c, defaultedOptions())), { | ||
defer: true | ||
}) | ||
); | ||
const [state, setState] = createStore( | ||
@@ -128,13 +126,21 @@ observer().getOptimisticResult(defaultedOptions()) | ||
const reconcileOptions = obs.options.reconcile; | ||
setState((store) => { | ||
return reconcileFn( | ||
store, | ||
result, | ||
reconcileOptions === void 0 ? false : reconcileOptions | ||
); | ||
}); | ||
if (queryResource()?.data && result.data && !queryResource.loading && isRestoring()) | ||
if (queryResource()?.data && result.data && !queryResource.loading) { | ||
setState((store) => { | ||
return reconcileFn( | ||
store, | ||
result, | ||
reconcileOptions === void 0 ? false : reconcileOptions | ||
); | ||
}); | ||
mutate(state); | ||
else | ||
} else { | ||
setState((store) => { | ||
return reconcileFn( | ||
store, | ||
result, | ||
reconcileOptions === void 0 ? false : reconcileOptions | ||
); | ||
}); | ||
refetch(); | ||
} | ||
})(); | ||
@@ -148,8 +154,9 @@ }); | ||
return new Promise((resolve, reject) => { | ||
if (isServer) | ||
if (isServer) { | ||
unsubscribe = createServerSubscriber(resolve, reject); | ||
else if (!unsubscribe && !isRestoring()) | ||
} else if (!unsubscribe && !isRestoring()) { | ||
unsubscribe = createClientSubscriber(); | ||
} | ||
obs.updateResult(); | ||
if (!state.isLoading && !isRestoring()) { | ||
if (!state.isLoading) { | ||
const query = obs.getCurrentQuery(); | ||
@@ -204,13 +211,21 @@ resolve(hydratableObserverResult(query, state)); | ||
on( | ||
[isRestoring, observer], | ||
([restoring]) => { | ||
const _unsubscribe = unsubscribe; | ||
queueMicrotask(() => _unsubscribe?.()); | ||
unsubscribe = null; | ||
if (!restoring) | ||
refetch(); | ||
client, | ||
(c) => { | ||
if (unsubscribe) { | ||
unsubscribe(); | ||
} | ||
const newObserver = new Observer(c, defaultedOptions()); | ||
unsubscribe = createClientSubscriber(); | ||
setObserver(newObserver); | ||
}, | ||
{ defer: true } | ||
{ | ||
defer: true | ||
} | ||
) | ||
); | ||
createComputed(() => { | ||
if (!isRestoring()) { | ||
refetch(); | ||
} | ||
}); | ||
onCleanup(() => { | ||
@@ -229,7 +244,3 @@ if (unsubscribe) { | ||
}, | ||
{ | ||
// Defer because we don't need to trigger on first render | ||
// This only cares about changes to options after the observer is created | ||
defer: true | ||
} | ||
{ defer: true } | ||
) | ||
@@ -325,4 +336,2 @@ ); | ||
} | ||
function noop() { | ||
} | ||
function useIsMutating(filters, queryClient) { | ||
@@ -329,0 +338,0 @@ const client = createMemo(() => useQueryClient(queryClient?.())); |
import { notifyManager, QueryClient as QueryClient$1, MutationObserver, replaceEqualDeep, QueriesObserver, hydrate, QueryObserver, InfiniteQueryObserver } from '@tanstack/query-core'; | ||
export * from '@tanstack/query-core'; | ||
import { batch, createContext, useContext, createRenderEffect, onCleanup, createMemo, createSignal, createComputed, on, createEffect, mergeProps, createResource, onMount, untrack } from 'solid-js'; | ||
import { batch, createContext, useContext, createRenderEffect, onCleanup, createMemo, createSignal, createComputed, on, createEffect, mergeProps, createResource, onMount } from 'solid-js'; | ||
import { createComponent, isServer } from 'solid-js/web'; | ||
@@ -47,2 +47,4 @@ import { createStore, unwrap, reconcile } from 'solid-js/store'; | ||
} | ||
function noop() { | ||
} | ||
var IsRestoringContext = createContext(() => false); | ||
@@ -89,19 +91,15 @@ var useIsRestoring = () => useContext(IsRestoringContext); | ||
const isRestoring = useIsRestoring(); | ||
const defaultedOptions = createMemo( | ||
() => mergeProps(client()?.defaultQueryOptions(options()) || {}, { | ||
get _optimisticResults() { | ||
return isRestoring() ? "isRestoring" : "optimistic"; | ||
}, | ||
structuralSharing: false, | ||
...isServer && { retry: false, throwOnError: true } | ||
}) | ||
); | ||
const defaultedOptions = createMemo(() => { | ||
const defaultOptions = client().defaultQueryOptions(options()); | ||
defaultOptions._optimisticResults = isRestoring() ? "isRestoring" : "optimistic"; | ||
defaultOptions.structuralSharing = false; | ||
if (isServer) { | ||
defaultOptions.retry = false; | ||
defaultOptions.throwOnError = true; | ||
} | ||
return defaultOptions; | ||
}); | ||
const [observer, setObserver] = createSignal( | ||
new Observer(client(), untrack(defaultedOptions)) | ||
new Observer(client(), defaultedOptions()) | ||
); | ||
createComputed( | ||
on(client, (c) => setObserver(new Observer(c, defaultedOptions())), { | ||
defer: true | ||
}) | ||
); | ||
const [state, setState] = createStore( | ||
@@ -128,13 +126,21 @@ observer().getOptimisticResult(defaultedOptions()) | ||
const reconcileOptions = obs.options.reconcile; | ||
setState((store) => { | ||
return reconcileFn( | ||
store, | ||
result, | ||
reconcileOptions === void 0 ? false : reconcileOptions | ||
); | ||
}); | ||
if (queryResource()?.data && result.data && !queryResource.loading && isRestoring()) | ||
if (queryResource()?.data && result.data && !queryResource.loading) { | ||
setState((store) => { | ||
return reconcileFn( | ||
store, | ||
result, | ||
reconcileOptions === void 0 ? false : reconcileOptions | ||
); | ||
}); | ||
mutate(state); | ||
else | ||
} else { | ||
setState((store) => { | ||
return reconcileFn( | ||
store, | ||
result, | ||
reconcileOptions === void 0 ? false : reconcileOptions | ||
); | ||
}); | ||
refetch(); | ||
} | ||
})(); | ||
@@ -148,8 +154,9 @@ }); | ||
return new Promise((resolve, reject) => { | ||
if (isServer) | ||
if (isServer) { | ||
unsubscribe = createServerSubscriber(resolve, reject); | ||
else if (!unsubscribe && !isRestoring()) | ||
} else if (!unsubscribe && !isRestoring()) { | ||
unsubscribe = createClientSubscriber(); | ||
} | ||
obs.updateResult(); | ||
if (!state.isLoading && !isRestoring()) { | ||
if (!state.isLoading) { | ||
const query = obs.getCurrentQuery(); | ||
@@ -204,13 +211,21 @@ resolve(hydratableObserverResult(query, state)); | ||
on( | ||
[isRestoring, observer], | ||
([restoring]) => { | ||
const _unsubscribe = unsubscribe; | ||
queueMicrotask(() => _unsubscribe?.()); | ||
unsubscribe = null; | ||
if (!restoring) | ||
refetch(); | ||
client, | ||
(c) => { | ||
if (unsubscribe) { | ||
unsubscribe(); | ||
} | ||
const newObserver = new Observer(c, defaultedOptions()); | ||
unsubscribe = createClientSubscriber(); | ||
setObserver(newObserver); | ||
}, | ||
{ defer: true } | ||
{ | ||
defer: true | ||
} | ||
) | ||
); | ||
createComputed(() => { | ||
if (!isRestoring()) { | ||
refetch(); | ||
} | ||
}); | ||
onCleanup(() => { | ||
@@ -229,7 +244,3 @@ if (unsubscribe) { | ||
}, | ||
{ | ||
// Defer because we don't need to trigger on first render | ||
// This only cares about changes to options after the observer is created | ||
defer: true | ||
} | ||
{ defer: true } | ||
) | ||
@@ -325,4 +336,2 @@ ); | ||
} | ||
function noop() { | ||
} | ||
function useIsMutating(filters, queryClient) { | ||
@@ -329,0 +338,0 @@ const client = createMemo(() => useQueryClient(queryClient?.())); |
{ | ||
"name": "@tanstack/solid-query", | ||
"version": "5.24.1", | ||
"version": "5.24.2", | ||
"description": "Primitives for managing, caching and syncing asynchronous and remote data in Solid", | ||
@@ -51,3 +51,3 @@ "author": "tannerlinsley", | ||
"solid-js": "^1.8.14", | ||
"@tanstack/query-core": "5.24.1" | ||
"@tanstack/query-core": "5.24.2" | ||
}, | ||
@@ -68,4 +68,5 @@ "devDependencies": { | ||
"test:build": "publint --strict", | ||
"build": "tsup" | ||
"build": "tsup", | ||
"build:watch": "tsup --watch" | ||
} | ||
} |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable @typescript-eslint/no-unnecessary-condition */ | ||
// Had to disable the lint rule because isServer type is defined as false | ||
@@ -12,6 +11,4 @@ // in solid-js/web package. I'll create a GitHub issue with them to see | ||
createSignal, | ||
mergeProps, | ||
on, | ||
onCleanup, | ||
untrack, | ||
} from 'solid-js' | ||
@@ -128,22 +125,18 @@ import { createStore, reconcile, unwrap } from 'solid-js/store' | ||
const defaultedOptions = createMemo(() => | ||
mergeProps(client()?.defaultQueryOptions(options()) || {}, { | ||
get _optimisticResults() { | ||
return isRestoring() ? 'isRestoring' : 'optimistic' | ||
}, | ||
structuralSharing: false, | ||
...(isServer && { retry: false, throwOnError: true }), | ||
}), | ||
) | ||
const defaultedOptions = createMemo(() => { | ||
const defaultOptions = client().defaultQueryOptions(options()) | ||
defaultOptions._optimisticResults = isRestoring() | ||
? 'isRestoring' | ||
: 'optimistic' | ||
defaultOptions.structuralSharing = false | ||
if (isServer) { | ||
defaultOptions.retry = false | ||
defaultOptions.throwOnError = true | ||
} | ||
return defaultOptions | ||
}) | ||
const [observer, setObserver] = createSignal( | ||
new Observer(client(), untrack(defaultedOptions)), | ||
new Observer(client(), defaultedOptions()), | ||
) | ||
// we set the value in a computed because `createMemo` | ||
// returns undefined during transitions | ||
createComputed( | ||
on(client, (c) => setObserver(new Observer(c, defaultedOptions())), { | ||
defer: true, | ||
}), | ||
) | ||
@@ -182,19 +175,23 @@ const [state, setState] = createStore<QueryObserverResult<TData, TError>>( | ||
setState((store) => { | ||
return reconcileFn( | ||
store, | ||
result, | ||
reconcileOptions === undefined ? false : reconcileOptions, | ||
) | ||
}) | ||
// If the query has data we don't suspend but instead mutate the resource | ||
// This could happen when placeholderData/initialData is defined | ||
if ( | ||
queryResource()?.data && | ||
result.data && | ||
!queryResource.loading && | ||
isRestoring() | ||
) | ||
if (queryResource()?.data && result.data && !queryResource.loading) { | ||
setState((store) => { | ||
return reconcileFn( | ||
store, | ||
result, | ||
reconcileOptions === undefined ? false : reconcileOptions, | ||
) | ||
}) | ||
mutate(state) | ||
else refetch() | ||
} else { | ||
setState((store) => { | ||
return reconcileFn( | ||
store, | ||
result, | ||
reconcileOptions === undefined ? false : reconcileOptions, | ||
) | ||
}) | ||
refetch() | ||
} | ||
})() | ||
@@ -215,9 +212,10 @@ }) | ||
return new Promise((resolve, reject) => { | ||
if (isServer) unsubscribe = createServerSubscriber(resolve, reject) | ||
else if (!unsubscribe && !isRestoring()) | ||
if (isServer) { | ||
unsubscribe = createServerSubscriber(resolve, reject) | ||
} else if (!unsubscribe && !isRestoring()) { | ||
unsubscribe = createClientSubscriber() | ||
} | ||
obs.updateResult() | ||
if (!state.isLoading && !isRestoring()) { | ||
if (!state.isLoading) { | ||
const query = obs.getCurrentQuery() | ||
@@ -282,13 +280,23 @@ resolve(hydratableObserverResult(query, state)) | ||
on( | ||
[isRestoring, observer], | ||
([restoring]) => { | ||
const _unsubscribe = unsubscribe | ||
queueMicrotask(() => _unsubscribe?.()) | ||
unsubscribe = null | ||
if (!restoring) refetch() | ||
client, | ||
(c) => { | ||
if (unsubscribe) { | ||
unsubscribe() | ||
} | ||
const newObserver = new Observer(c, defaultedOptions()) | ||
unsubscribe = createClientSubscriber() | ||
setObserver(newObserver) | ||
}, | ||
{ defer: true }, | ||
{ | ||
defer: true, | ||
}, | ||
), | ||
) | ||
createComputed(() => { | ||
if (!isRestoring()) { | ||
refetch() | ||
} | ||
}) | ||
onCleanup(() => { | ||
@@ -308,7 +316,3 @@ if (unsubscribe) { | ||
}, | ||
{ | ||
// Defer because we don't need to trigger on first render | ||
// This only cares about changes to options after the observer is created | ||
defer: true, | ||
}, | ||
{ defer: true }, | ||
), | ||
@@ -315,0 +319,0 @@ ) |
@@ -5,3 +5,3 @@ import { MutationObserver } from '@tanstack/query-core' | ||
import { useQueryClient } from './QueryClientProvider' | ||
import { shouldThrowError } from './utils' | ||
import { noop, shouldThrowError } from './utils' | ||
import type { DefaultError } from '@tanstack/query-core' | ||
@@ -78,3 +78,1 @@ import type { QueryClient } from './QueryClient' | ||
} | ||
function noop() {} |
@@ -12,1 +12,3 @@ export function shouldThrowError<T extends (...args: Array<any>) => boolean>( | ||
} | ||
export function noop() {} |
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
436142
13208
+ Added@tanstack/query-core@5.24.2(transitive)
- Removed@tanstack/query-core@5.24.1(transitive)
Updated@tanstack/query-core@5.24.2