Skip to content

Commit

Permalink
Merge branch 'main' into react-query/prefetch/queryClient-param
Browse files Browse the repository at this point in the history
  • Loading branch information
TkDodo authored Sep 6, 2024
2 parents d16287b + 6799b82 commit e9d8529
Show file tree
Hide file tree
Showing 37 changed files with 160 additions and 124 deletions.
4 changes: 2 additions & 2 deletions examples/solid/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"@astrojs/solid-js": "^4.4.0",
"@astrojs/tailwind": "^5.1.0",
"@astrojs/vercel": "^7.7.2",
"@tanstack/solid-query": "^5.54.1",
"@tanstack/solid-query-devtools": "^5.54.1",
"@tanstack/solid-query": "^5.54.2",
"@tanstack/solid-query-devtools": "^5.54.2",
"astro": "^4.12.2",
"solid-js": "^1.8.19",
"tailwindcss": "^3.4.7",
Expand Down
4 changes: 2 additions & 2 deletions examples/solid/basic-graphql-request/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"test:types": "tsc"
},
"dependencies": {
"@tanstack/solid-query": "^5.54.1",
"@tanstack/solid-query-devtools": "^5.54.1",
"@tanstack/solid-query": "^5.54.2",
"@tanstack/solid-query-devtools": "^5.54.2",
"graphql": "^16.9.0",
"graphql-request": "^7.1.0",
"solid-js": "^1.8.19"
Expand Down
4 changes: 2 additions & 2 deletions examples/solid/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"test:types": "tsc"
},
"dependencies": {
"@tanstack/solid-query": "^5.54.1",
"@tanstack/solid-query-devtools": "^5.54.1",
"@tanstack/solid-query": "^5.54.2",
"@tanstack/solid-query-devtools": "^5.54.2",
"solid-js": "^1.8.19"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions examples/solid/default-query-function/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"test:types": "tsc"
},
"dependencies": {
"@tanstack/solid-query": "^5.54.1",
"@tanstack/solid-query-devtools": "^5.54.1",
"@tanstack/solid-query": "^5.54.2",
"@tanstack/solid-query-devtools": "^5.54.2",
"solid-js": "^1.8.19"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions examples/solid/simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"test:types": "tsc"
},
"dependencies": {
"@tanstack/solid-query": "^5.54.1",
"@tanstack/solid-query-devtools": "^5.54.1",
"@tanstack/solid-query": "^5.54.2",
"@tanstack/solid-query-devtools": "^5.54.2",
"solid-js": "^1.8.19"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions examples/solid/solid-start-streaming/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"@solidjs/meta": "^0.29.4",
"@solidjs/router": "^0.14.1",
"@solidjs/start": "^1.0.6",
"@tanstack/solid-query": "^5.54.1",
"@tanstack/solid-query-devtools": "^5.54.1",
"@tanstack/solid-query": "^5.54.2",
"@tanstack/solid-query-devtools": "^5.54.2",
"solid-js": "^1.8.19",
"vinxi": "^0.4.1"
},
Expand Down
4 changes: 2 additions & 2 deletions examples/svelte/auto-refetching/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"test:types": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json"
},
"dependencies": {
"@tanstack/svelte-query": "^5.54.1",
"@tanstack/svelte-query-devtools": "^5.54.1"
"@tanstack/svelte-query": "^5.54.2",
"@tanstack/svelte-query-devtools": "^5.54.2"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^3.2.2",
Expand Down
6 changes: 3 additions & 3 deletions examples/svelte/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
},
"dependencies": {
"@tanstack/query-sync-storage-persister": "^5.54.1",
"@tanstack/svelte-query": "^5.54.1",
"@tanstack/svelte-query-devtools": "^5.54.1",
"@tanstack/svelte-query-persist-client": "^5.54.1"
"@tanstack/svelte-query": "^5.54.2",
"@tanstack/svelte-query-devtools": "^5.54.2",
"@tanstack/svelte-query-persist-client": "^5.54.2"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^3.2.2",
Expand Down
4 changes: 2 additions & 2 deletions examples/svelte/load-more-infinite-scroll/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"test:types": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json"
},
"dependencies": {
"@tanstack/svelte-query": "^5.54.1",
"@tanstack/svelte-query-devtools": "^5.54.1"
"@tanstack/svelte-query": "^5.54.2",
"@tanstack/svelte-query-devtools": "^5.54.2"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^3.2.2",
Expand Down
4 changes: 2 additions & 2 deletions examples/svelte/optimistic-updates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"test:types": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json"
},
"dependencies": {
"@tanstack/svelte-query": "^5.54.1",
"@tanstack/svelte-query-devtools": "^5.54.1"
"@tanstack/svelte-query": "^5.54.2",
"@tanstack/svelte-query-devtools": "^5.54.2"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^3.2.2",
Expand Down
4 changes: 2 additions & 2 deletions examples/svelte/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"test:types": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json"
},
"dependencies": {
"@tanstack/svelte-query": "^5.54.1",
"@tanstack/svelte-query-devtools": "^5.54.1"
"@tanstack/svelte-query": "^5.54.2",
"@tanstack/svelte-query-devtools": "^5.54.2"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^3.2.2",
Expand Down
4 changes: 2 additions & 2 deletions examples/svelte/simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"test:types": "svelte-check --tsconfig ./tsconfig.json"
},
"dependencies": {
"@tanstack/svelte-query": "^5.54.1",
"@tanstack/svelte-query-devtools": "^5.54.1"
"@tanstack/svelte-query": "^5.54.2",
"@tanstack/svelte-query-devtools": "^5.54.2"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^3.1.1",
Expand Down
4 changes: 2 additions & 2 deletions examples/svelte/ssr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"test:types": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json"
},
"dependencies": {
"@tanstack/svelte-query": "^5.54.1",
"@tanstack/svelte-query-devtools": "^5.54.1"
"@tanstack/svelte-query": "^5.54.2",
"@tanstack/svelte-query-devtools": "^5.54.2"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^3.2.2",
Expand Down
4 changes: 2 additions & 2 deletions examples/svelte/star-wars/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"test:types": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json"
},
"dependencies": {
"@tanstack/svelte-query": "^5.54.1",
"@tanstack/svelte-query-devtools": "^5.54.1"
"@tanstack/svelte-query": "^5.54.2",
"@tanstack/svelte-query-devtools": "^5.54.2"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^3.2.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/vue/2.6-basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"_preview": "vite preview"
},
"dependencies": {
"@tanstack/vue-query": "^5.54.1",
"@tanstack/vue-query": "^5.54.2",
"@vue/composition-api": "1.7.2",
"vue": "2.6.14",
"vue-template-compiler": "2.6.14"
Expand Down
2 changes: 1 addition & 1 deletion examples/vue/2.7-basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"_serve": "vite preview"
},
"dependencies": {
"@tanstack/vue-query": "^5.54.1",
"@tanstack/vue-query": "^5.54.2",
"vue": "2.7.16",
"vue-template-compiler": "2.7.16"
},
Expand Down
4 changes: 2 additions & 2 deletions examples/vue/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"preview": "vite preview"
},
"dependencies": {
"@tanstack/vue-query": "^5.54.1",
"@tanstack/vue-query-devtools": "^5.54.1",
"@tanstack/vue-query": "^5.54.2",
"@tanstack/vue-query-devtools": "^5.54.2",
"vue": "^3.4.27"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/vue/dependent-queries/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"preview": "vite preview"
},
"dependencies": {
"@tanstack/vue-query": "^5.54.1",
"@tanstack/vue-query": "^5.54.2",
"vue": "^3.4.27"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/vue/nuxt3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"_start": "node .output/server/index.mjs"
},
"dependencies": {
"@tanstack/vue-query": "^5.54.1"
"@tanstack/vue-query": "^5.54.2"
},
"devDependencies": {
"nuxt": "^3.12.4"
Expand Down
2 changes: 1 addition & 1 deletion examples/vue/persister/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@tanstack/query-core": "^5.54.1",
"@tanstack/query-persist-client-core": "^5.54.1",
"@tanstack/query-sync-storage-persister": "^5.54.1",
"@tanstack/vue-query": "^5.54.1",
"@tanstack/vue-query": "^5.54.2",
"idb-keyval": "^6.2.1",
"vue": "^3.4.27"
},
Expand Down
4 changes: 2 additions & 2 deletions examples/vue/simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"preview": "vite preview"
},
"dependencies": {
"@tanstack/vue-query": "^5.54.1",
"@tanstack/vue-query-devtools": "^5.54.1",
"@tanstack/vue-query": "^5.54.2",
"@tanstack/vue-query-devtools": "^5.54.2",
"vue": "^3.4.27"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/solid-query-devtools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/solid-query-devtools",
"version": "5.54.1",
"version": "5.54.2",
"description": "Developer tools to interact with and visualize the TanStack/solid-query Query cache",
"author": "tannerlinsley",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/solid-query-persist-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/solid-query-persist-client",
"version": "5.54.1",
"version": "5.54.2",
"description": "Solid.js bindings to work with persisters in TanStack/solid-query",
"author": "tannerlinsley",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/solid-query/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/solid-query",
"version": "5.54.1",
"version": "5.54.2",
"description": "Primitives for managing, caching and syncing asynchronous and remote data in Solid",
"author": "tannerlinsley",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte-query-devtools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/svelte-query-devtools",
"version": "5.54.1",
"version": "5.54.2",
"description": "Developer tools to interact with and visualize the TanStack/svelte-query cache",
"author": "Lachlan Collins",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte-query-persist-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/svelte-query-persist-client",
"version": "5.54.1",
"version": "5.54.2",
"description": "Svelte bindings to work with persisters in TanStack/svelte-query",
"author": "Lachlan Collins",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte-query/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/svelte-query",
"version": "5.54.1",
"version": "5.54.2",
"description": "Primitives for managing, caching and syncing asynchronous and remote data in Svelte",
"author": "Lachlan Collins",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-query-devtools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/vue-query-devtools",
"version": "5.54.1",
"version": "5.54.2",
"description": "Developer tools to interact with and visualize the TanStack/vue-query cache",
"author": "tannerlinsley",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-query/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/vue-query",
"version": "5.54.1",
"version": "5.54.2",
"description": "Hooks for managing, caching and syncing asynchronous and remote data in Vue",
"author": "Damian Osipiuk",
"license": "MIT",
Expand Down
15 changes: 12 additions & 3 deletions packages/vue-query/src/useBaseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import {
computed,
getCurrentScope,
onScopeDispose,
reactive,
readonly,
shallowReactive,
shallowReadonly,
toRefs,
watch,
} from 'vue-demi'
Expand Down Expand Up @@ -105,7 +106,7 @@ export function useBaseQuery<
})

const observer = new Observer(client, defaultedOptions.value)
const state = reactive(observer.getCurrentResult())
const state = shallowReactive(observer.getCurrentResult())

let unsubscribe = () => {
// noop
Expand Down Expand Up @@ -201,7 +202,15 @@ export function useBaseQuery<
},
)

const object: any = toRefs(readonly(state))
const readonlyState =
process.env.NODE_ENV === 'production'
? state
: // @ts-expect-error
defaultedOptions.value.shallow
? shallowReadonly(state)
: readonly(state)

const object: any = toRefs(readonlyState)
for (const key in state) {
if (typeof state[key as keyof typeof state] === 'function') {
object[key] = state[key as keyof typeof state]
Expand Down
2 changes: 2 additions & 0 deletions packages/vue-query/src/useInfiniteQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export type UseInfiniteQueryOptions<
TPageParam
>[Property]
>
} & {
shallow?: boolean
}

export type UseInfiniteQueryReturnType<TData, TError> = UseBaseQueryReturnType<
Expand Down
23 changes: 18 additions & 5 deletions packages/vue-query/src/useMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import {
computed,
getCurrentScope,
onScopeDispose,
reactive,
readonly,
shallowReactive,
shallowReadonly,
toRefs,
watch,
} from 'vue-demi'
Expand All @@ -26,12 +27,17 @@ type MutationResult<TData, TError, TVariables, TContext> = DistributiveOmit<
'mutate' | 'reset'
>

type UseMutationOptionsBase<TData, TError, TVariables, TContext> =
MutationObserverOptions<TData, TError, TVariables, TContext> & {
shallow?: boolean
}

export type UseMutationOptions<
TData = unknown,
TError = DefaultError,
TVariables = void,
TContext = unknown,
> = MaybeRefDeep<MutationObserverOptions<TData, TError, TVariables, TContext>>
> = MaybeRefDeep<UseMutationOptionsBase<TData, TError, TVariables, TContext>>

type MutateSyncFunction<
TData = unknown,
Expand Down Expand Up @@ -61,7 +67,7 @@ export function useMutation<
TContext = unknown,
>(
mutationOptions: MaybeRefDeep<
MutationObserverOptions<TData, TError, TVariables, TContext>
UseMutationOptionsBase<TData, TError, TVariables, TContext>
>,
queryClient?: QueryClient,
): UseMutationReturnType<TData, TError, TVariables, TContext> {
Expand All @@ -78,7 +84,7 @@ export function useMutation<
return client.defaultMutationOptions(cloneDeepUnref(mutationOptions))
})
const observer = new MutationObserver(client, options.value)
const state = reactive(observer.getCurrentResult())
const state = shallowReactive(observer.getCurrentResult())

const unsubscribe = observer.subscribe((result) => {
updateState(state, result)
Expand All @@ -101,7 +107,14 @@ export function useMutation<
unsubscribe()
})

const resultRefs = toRefs(readonly(state)) as unknown as ToRefs<
const readonlyState =
process.env.NODE_ENV === 'production'
? state
: options.value.shallow
? shallowReadonly(state)
: readonly(state)

const resultRefs = toRefs(readonlyState) as ToRefs<
Readonly<MutationResult<TData, TError, TVariables, TContext>>
>

Expand Down
Loading

0 comments on commit e9d8529

Please sign in to comment.