Skip to content

Commit 3a2e2d9

Browse files
fix(vue-query): unify shallow flag behaviour (#9050)
1 parent b63a1d0 commit 3a2e2d9

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

packages/vue-query/src/useBaseQuery.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
computed,
33
getCurrentScope,
44
onScopeDispose,
5+
reactive,
56
readonly,
67
shallowReactive,
78
shallowReadonly,
@@ -106,7 +107,10 @@ export function useBaseQuery<
106107
})
107108

108109
const observer = new Observer(client, defaultedOptions.value)
109-
const state = shallowReactive(observer.getCurrentResult())
110+
// @ts-expect-error
111+
const state = defaultedOptions.value.shallow
112+
? shallowReactive(observer.getCurrentResult())
113+
: reactive(observer.getCurrentResult())
110114

111115
let unsubscribe = () => {
112116
// noop
@@ -202,13 +206,10 @@ export function useBaseQuery<
202206
},
203207
)
204208

205-
const readonlyState =
206-
process.env.NODE_ENV === 'production'
207-
? state
208-
: // @ts-expect-error
209-
defaultedOptions.value.shallow
210-
? shallowReadonly(state)
211-
: readonly(state)
209+
// @ts-expect-error
210+
const readonlyState = defaultedOptions.value.shallow
211+
? shallowReadonly(state)
212+
: readonly(state)
212213

213214
const object: any = toRefs(readonlyState)
214215
for (const key in state) {

packages/vue-query/src/useMutation.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
computed,
33
getCurrentScope,
44
onScopeDispose,
5+
reactive,
56
readonly,
67
shallowReactive,
78
shallowReadonly,
@@ -87,7 +88,9 @@ export function useMutation<
8788
return client.defaultMutationOptions(cloneDeepUnref(mutationOptions))
8889
})
8990
const observer = new MutationObserver(client, options.value)
90-
const state = shallowReactive(observer.getCurrentResult())
91+
const state = options.value.shallow
92+
? shallowReactive(observer.getCurrentResult())
93+
: reactive(observer.getCurrentResult())
9194

9295
const unsubscribe = observer.subscribe((result) => {
9396
updateState(state, result)
@@ -110,12 +113,9 @@ export function useMutation<
110113
unsubscribe()
111114
})
112115

113-
const readonlyState =
114-
process.env.NODE_ENV === 'production'
115-
? state
116-
: options.value.shallow
117-
? shallowReadonly(state)
118-
: readonly(state)
116+
const readonlyState = options.value.shallow
117+
? shallowReadonly(state)
118+
: readonly(state)
119119

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

packages/vue-query/src/useQueries.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,7 @@ export function useQueries<
344344
unsubscribe()
345345
})
346346

347-
return process.env.NODE_ENV === 'production'
348-
? state
349-
: options.shallow
350-
? shallowReadonly(state)
351-
: (readonly(state) as Readonly<Ref<TCombinedResult>>)
347+
return options.shallow
348+
? shallowReadonly(state)
349+
: (readonly(state) as Readonly<Ref<TCombinedResult>>)
352350
}

0 commit comments

Comments
 (0)