Skip to content

Commit a2dac5c

Browse files
committed
refactor!: changed resultObservable deep -> ref globally
1 parent a454dbf commit a2dac5c

10 files changed

Lines changed: 28 additions & 19 deletions

File tree

.changeset/friendly-mails-cheat.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"mobx-tanstack-query": major
3+
---
4+
5+
Changed the global default for `resultObservable` from `'deep'` to `'ref'` for both `Query` and `Mutation`.
6+
7+
If your app relies on deep MobX tracking of nested fields inside query or mutation results, set `resultObservable: 'deep'` explicitly (locally or via `QueryClient` defaults).

docs/api/Mutation.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,9 @@ const mutation = new Mutation({
179179

180180
Chooses how MobX observes the mutation **`result`** property (the `MutationObserverResult`). The library applies `annotation.observable()` from [`yummies/mobx`](https://github.com/js2me/yummies). [`Query`](https://js2me.github.io/mobx-tanstack-query/api/Query.html#resultobservable-queryfeature) stores the payload on a private `_result` and exposes TanStack fields via getters; **`Mutation` decorates the public `result` field directly** — there is no `_result`.
181181

182-
- **Default** — when omitted, behaviour matches **`'deep'`** (deep observability for plain objects and arrays in the result).
182+
- **Default** — when omitted, behaviour matches **`'ref'`** (only the result object reference is tracked).
183183
- **`'ref'`** — only the reference to the result object is tracked; reactions run when the whole result is replaced, not when nested fields change in place.
184+
- **`'deep'`** — deep observability for plain objects and arrays in the result.
184185
- **`'shallow'`** / **`'struct'`** — shallow or structural comparison for nested properties.
185186
- **`false`** — do not decorate `result` (rare; you lose automatic MobX tracking for the result blob).
186187

@@ -216,10 +217,10 @@ Subscribe when mutation has been finished with failure
216217

217218
Reset current mutation
218219

219-
### property `result` <Badge type="info" text="observable.deep" />
220+
### property `result` <Badge type="info" text="observable.ref" />
220221

221222
Mutation result (The same as returns the [`useMutation` hook](https://tanstack.com/query/latest/docs/framework/react/reference/useMutation))
222223

223-
::: info `observable.deep` is configurable
224-
The badge reflects the **default**: the public `result` property is decorated as deep observable (unlike `Query`, which uses a private `_result` behind getters). Change the MobX flavour with [`resultObservable`](#resultobservable-mutationfeature) (`ref`, `shallow`, `struct`, `true`, or `false`).
224+
::: info `observable.ref` is configurable
225+
The badge reflects the **default**: the public `result` property is decorated as `observable.ref` (unlike `Query`, which uses a private `_result` behind getters). Change the MobX flavour with [`resultObservable`](#resultobservable-mutationfeature) (`deep`, `shallow`, `struct`, `true`, or `false`).
225226
:::

docs/api/Query.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,12 @@ The underlying query observer instance from tanstack query core package.
291291
Any time when you trying to get access to `result` property this field sets as `true`
292292
This field is needed for `enableOnDemand` option
293293

294-
### `result: QueryObserverResult` <Badge type="info" text="observable.deep" />
294+
### `result: QueryObserverResult` <Badge type="info" text="observable.ref" />
295295

296296
Query original result (The same as returns the [`useQuery` hook](https://tanstack.com/query/latest/docs/framework/react/reference/useQuery))
297297

298-
::: info `observable.deep` is configurable
299-
The badge reflects the **default**: the internal `_result` field is decorated as deep observable. You can change the MobX flavour (`ref`, `shallow`, `struct`, `true`, or `false`) with the [`resultObservable`](#resultobservable-queryfeature) query feature.
298+
::: info `observable.ref` is configurable
299+
The badge reflects the **default**: the internal `_result` field is decorated as `observable.ref`. You can change the MobX flavour (`deep`, `shallow`, `struct`, `true`, or `false`) with the [`resultObservable`](#resultobservable-queryfeature) query feature.
300300
:::
301301

302302
### `setData(updater, options)`
@@ -785,8 +785,9 @@ const query = new Query({
785785

786786
Chooses how MobX observes the internal TanStack Query result object (`_result`). The library applies [`annotation.observable()`](https://github.com/js2me/yummies) from `yummies/mobx`, so this maps directly to MobX flavours: `ref`, `deep`, `shallow`, `struct`, or `true` / `false`.
787787

788-
- **Default** — when omitted, behaviour matches **`'deep'`** (deep observability for plain objects and arrays in the result).
788+
- **Default** — when omitted, behaviour matches **`'ref'`** (only the result object reference is tracked).
789789
- **`'ref'`** — only the reference to the result object is tracked; use when the observer should react when the whole result is replaced, not when nested fields change in place.
790+
- **`'deep'`** — deep observability for plain objects and arrays in the result.
790791
- **`'shallow'`** / **`'struct'`** — shallow or structural comparison for nested properties.
791792
- **`false`** — do not decorate `_result` with an observable annotation (rare; you lose automatic MobX tracking for the result blob).
792793

src/base-query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export abstract class BaseQuery<
133133
autoRemovePreviousQuery:
134134
config.autoRemovePreviousQuery ?? qf?.autoRemovePreviousQuery,
135135
resultObservable:
136-
config.resultObservable ?? qf?.resultObservable ?? 'deep',
136+
config.resultObservable ?? qf?.resultObservable ?? 'ref',
137137
};
138138
}
139139

src/infinite-query.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ describe('InfiniteQuery', () => {
12171217

12181218
it('basic', () => {
12191219
const query = createInfiniteQuery();
1220-
expect(types.isProxy(query.getInternalResult())).toBe(true);
1220+
expect(types.isProxy(query.getInternalResult())).toBe(false);
12211221
});
12221222

12231223
it('(query: resultObservable: false)', () => {

src/mutation.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ describe('Mutation', () => {
247247

248248
it('basic', () => {
249249
const mutation = createMutation();
250-
expect(types.isProxy(mutation.getInternalResult())).toBe(true);
250+
expect(types.isProxy(mutation.getInternalResult())).toBe(false);
251251
});
252252

253253
it('(mutation: resultObservable: false)', () => {

src/mutation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export class Mutation<
176176
resultObservable:
177177
config.resultObservable ??
178178
qc.mutationFeatures?.resultObservable ??
179-
'deep',
179+
'ref',
180180
};
181181

182182
this.hooks = qc.hooks;

src/mutation.types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ export interface MutationFeatures {
5252
* and exposes fields via getters), `Mutation` decorates the public `result` field directly. Convenience fields
5353
* (`data`, `isPending`, `isError`, …) read from that object, so this option controls how deeply updates propagate.
5454
*
55-
* - `'deep'` — default when omitted; deep observability for plain objects and arrays.
55+
* - `'ref'` — default when omitted; tracks only the result reference.
56+
* - `'deep'` — deep observability for plain objects and arrays.
5657
* - `'shallow'` / `'struct'` — shallow or structural comparison for nested keys.
57-
* - `'ref'` — track only the result reference (useful when the whole result object is replaced each update).
5858
* - `true` — base `observable` (same as omitting the option).
5959
* - `false` — skip decorating `result` (no automatic MobX tracking for the result; advanced use only).
6060
*
61-
* @default 'deep'
61+
* @default 'ref'
6262
*
6363
* [**Documentation**](https://js2me.github.io/mobx-tanstack-query/api/Mutation.html#resultobservable-mutationfeature)
6464
*/

src/query.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4620,7 +4620,7 @@ describe('Query', () => {
46204620

46214621
it('basic', () => {
46224622
const query = createQuery();
4623-
expect(types.isProxy(query.getInternalResult())).toBe(true);
4623+
expect(types.isProxy(query.getInternalResult())).toBe(false);
46244624
});
46254625

46264626
it('(query: resultObservable: false)', () => {

src/query.types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,13 @@ export interface QueryFeatures {
194194
* `annotation.observable()` from `yummies/mobx`. Public fields (`data`, `status`, `isLoading`, …) read from
195195
* this object, so the option controls how deeply updates to the query result propagate to observers.
196196
*
197-
* - `'deep'` — default when omitted; deep observability for plain objects and arrays.
197+
* - `'ref'` — default when omitted; tracks only the result reference.
198+
* - `'deep'` — deep observability for plain objects and arrays.
198199
* - `'shallow'` / `'struct'` — shallow or structural comparison for nested keys.
199-
* - `'ref'` — track only the result reference (useful when the whole result object is replaced each update).
200200
* - `true` — base `observable` (same as omitting the option).
201201
* - `false` — skip decorating `_result` (no automatic MobX tracking for the result; advanced use only).
202202
*
203-
* @default 'deep'
203+
* @default 'ref'
204204
*
205205
* [**Documentation**](https://js2me.github.io/mobx-tanstack-query/api/Query.html#resultobservable-queryfeature)
206206
*/

0 commit comments

Comments
 (0)