@tanstack/solid-query 5.0.0-beta.0 → 5.0.0-beta.4
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/dev.cjs +23 -19
- package/build/dev.js +23 -19
- package/build/index.cjs +23 -16
- package/build/index.js +23 -16
- package/package.json +14 -11
- package/src/__tests__/createQuery.test.tsx +3 -3
- package/src/__tests__/useIsFetching.test.tsx +1 -1
- package/src/__tests__/useIsMutating.test.tsx +1 -1
- package/src/createBaseQuery.ts +57 -28
package/build/dev.cjs
CHANGED
|
@@ -57,6 +57,25 @@ function reconcileFn(store$1, result, reconcileOption) {
|
|
|
57
57
|
const newData = store.reconcile(result.data, { key: reconcileOption })(store$1.data);
|
|
58
58
|
return { ...result, data: newData };
|
|
59
59
|
}
|
|
60
|
+
var hydrateableObserverResult = (query, result) => {
|
|
61
|
+
if (!web.isServer)
|
|
62
|
+
return result;
|
|
63
|
+
return {
|
|
64
|
+
...store.unwrap(result),
|
|
65
|
+
// cast to refetch function should be safe, since we only remove it on the server,
|
|
66
|
+
// and refetch is not relevant on the server
|
|
67
|
+
refetch: void 0,
|
|
68
|
+
// hydrate() expects a QueryState object, which is similar but not
|
|
69
|
+
// quite the same as a QueryObserverResult object. Thus, for now, we're
|
|
70
|
+
// copying over the missing properties from state in order to support hydration
|
|
71
|
+
dataUpdateCount: query.state.dataUpdateCount,
|
|
72
|
+
fetchFailureCount: query.state.fetchFailureCount,
|
|
73
|
+
isInvalidated: query.state.isInvalidated,
|
|
74
|
+
// Unsetting these properties on the server since they might not be serializable
|
|
75
|
+
fetchFailureReason: null,
|
|
76
|
+
fetchMeta: null
|
|
77
|
+
};
|
|
78
|
+
};
|
|
60
79
|
function createBaseQuery(options, Observer, queryClient) {
|
|
61
80
|
const client = solidJs.createMemo(() => exports.useQueryClient(queryClient?.()));
|
|
62
81
|
const defaultedOptions = client().defaultQueryOptions(options());
|
|
@@ -74,26 +93,10 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
74
93
|
return observer.subscribe((result) => {
|
|
75
94
|
queryCore.notifyManager.batchCalls(() => {
|
|
76
95
|
const query = observer.getCurrentQuery();
|
|
77
|
-
const
|
|
78
|
-
const unwrappedResult = {
|
|
79
|
-
...rest,
|
|
80
|
-
// hydrate() expects a QueryState object, which is similar but not
|
|
81
|
-
// quite the same as a QueryObserverResult object. Thus, for now, we're
|
|
82
|
-
// copying over the missing properties from state in order to support hydration
|
|
83
|
-
dataUpdateCount: query.state.dataUpdateCount,
|
|
84
|
-
fetchFailureCount: query.state.fetchFailureCount,
|
|
85
|
-
// Removing these properties since they might not be serializable
|
|
86
|
-
// fetchFailureReason: query.state.fetchFailureReason,
|
|
87
|
-
// fetchMeta: query.state.fetchMeta,
|
|
88
|
-
isInvalidated: query.state.isInvalidated
|
|
89
|
-
};
|
|
96
|
+
const unwrappedResult = hydrateableObserverResult(query, result);
|
|
90
97
|
if (unwrappedResult.isError) {
|
|
91
|
-
{
|
|
92
|
-
console.error(unwrappedResult.error);
|
|
93
|
-
}
|
|
94
98
|
reject(unwrappedResult.error);
|
|
95
|
-
}
|
|
96
|
-
if (unwrappedResult.isSuccess) {
|
|
99
|
+
} else {
|
|
97
100
|
resolve(unwrappedResult);
|
|
98
101
|
}
|
|
99
102
|
})();
|
|
@@ -137,7 +140,8 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
137
140
|
}
|
|
138
141
|
}
|
|
139
142
|
if (!state.isLoading) {
|
|
140
|
-
|
|
143
|
+
const query = observer.getCurrentQuery();
|
|
144
|
+
resolve(hydrateableObserverResult(query, state));
|
|
141
145
|
}
|
|
142
146
|
});
|
|
143
147
|
},
|
package/build/dev.js
CHANGED
|
@@ -56,6 +56,25 @@ function reconcileFn(store, result, reconcileOption) {
|
|
|
56
56
|
const newData = reconcile(result.data, { key: reconcileOption })(store.data);
|
|
57
57
|
return { ...result, data: newData };
|
|
58
58
|
}
|
|
59
|
+
var hydrateableObserverResult = (query, result) => {
|
|
60
|
+
if (!isServer)
|
|
61
|
+
return result;
|
|
62
|
+
return {
|
|
63
|
+
...unwrap(result),
|
|
64
|
+
// cast to refetch function should be safe, since we only remove it on the server,
|
|
65
|
+
// and refetch is not relevant on the server
|
|
66
|
+
refetch: void 0,
|
|
67
|
+
// hydrate() expects a QueryState object, which is similar but not
|
|
68
|
+
// quite the same as a QueryObserverResult object. Thus, for now, we're
|
|
69
|
+
// copying over the missing properties from state in order to support hydration
|
|
70
|
+
dataUpdateCount: query.state.dataUpdateCount,
|
|
71
|
+
fetchFailureCount: query.state.fetchFailureCount,
|
|
72
|
+
isInvalidated: query.state.isInvalidated,
|
|
73
|
+
// Unsetting these properties on the server since they might not be serializable
|
|
74
|
+
fetchFailureReason: null,
|
|
75
|
+
fetchMeta: null
|
|
76
|
+
};
|
|
77
|
+
};
|
|
59
78
|
function createBaseQuery(options, Observer, queryClient) {
|
|
60
79
|
const client = createMemo(() => useQueryClient(queryClient?.()));
|
|
61
80
|
const defaultedOptions = client().defaultQueryOptions(options());
|
|
@@ -73,26 +92,10 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
73
92
|
return observer.subscribe((result) => {
|
|
74
93
|
notifyManager.batchCalls(() => {
|
|
75
94
|
const query = observer.getCurrentQuery();
|
|
76
|
-
const
|
|
77
|
-
const unwrappedResult = {
|
|
78
|
-
...rest,
|
|
79
|
-
// hydrate() expects a QueryState object, which is similar but not
|
|
80
|
-
// quite the same as a QueryObserverResult object. Thus, for now, we're
|
|
81
|
-
// copying over the missing properties from state in order to support hydration
|
|
82
|
-
dataUpdateCount: query.state.dataUpdateCount,
|
|
83
|
-
fetchFailureCount: query.state.fetchFailureCount,
|
|
84
|
-
// Removing these properties since they might not be serializable
|
|
85
|
-
// fetchFailureReason: query.state.fetchFailureReason,
|
|
86
|
-
// fetchMeta: query.state.fetchMeta,
|
|
87
|
-
isInvalidated: query.state.isInvalidated
|
|
88
|
-
};
|
|
95
|
+
const unwrappedResult = hydrateableObserverResult(query, result);
|
|
89
96
|
if (unwrappedResult.isError) {
|
|
90
|
-
{
|
|
91
|
-
console.error(unwrappedResult.error);
|
|
92
|
-
}
|
|
93
97
|
reject(unwrappedResult.error);
|
|
94
|
-
}
|
|
95
|
-
if (unwrappedResult.isSuccess) {
|
|
98
|
+
} else {
|
|
96
99
|
resolve(unwrappedResult);
|
|
97
100
|
}
|
|
98
101
|
})();
|
|
@@ -136,7 +139,8 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
136
139
|
}
|
|
137
140
|
}
|
|
138
141
|
if (!state.isLoading) {
|
|
139
|
-
|
|
142
|
+
const query = observer.getCurrentQuery();
|
|
143
|
+
resolve(hydrateableObserverResult(query, state));
|
|
140
144
|
}
|
|
141
145
|
});
|
|
142
146
|
},
|
package/build/index.cjs
CHANGED
|
@@ -57,6 +57,25 @@ function reconcileFn(store$1, result, reconcileOption) {
|
|
|
57
57
|
const newData = store.reconcile(result.data, { key: reconcileOption })(store$1.data);
|
|
58
58
|
return { ...result, data: newData };
|
|
59
59
|
}
|
|
60
|
+
var hydrateableObserverResult = (query, result) => {
|
|
61
|
+
if (!web.isServer)
|
|
62
|
+
return result;
|
|
63
|
+
return {
|
|
64
|
+
...store.unwrap(result),
|
|
65
|
+
// cast to refetch function should be safe, since we only remove it on the server,
|
|
66
|
+
// and refetch is not relevant on the server
|
|
67
|
+
refetch: void 0,
|
|
68
|
+
// hydrate() expects a QueryState object, which is similar but not
|
|
69
|
+
// quite the same as a QueryObserverResult object. Thus, for now, we're
|
|
70
|
+
// copying over the missing properties from state in order to support hydration
|
|
71
|
+
dataUpdateCount: query.state.dataUpdateCount,
|
|
72
|
+
fetchFailureCount: query.state.fetchFailureCount,
|
|
73
|
+
isInvalidated: query.state.isInvalidated,
|
|
74
|
+
// Unsetting these properties on the server since they might not be serializable
|
|
75
|
+
fetchFailureReason: null,
|
|
76
|
+
fetchMeta: null
|
|
77
|
+
};
|
|
78
|
+
};
|
|
60
79
|
function createBaseQuery(options, Observer, queryClient) {
|
|
61
80
|
const client = solidJs.createMemo(() => exports.useQueryClient(queryClient?.()));
|
|
62
81
|
const defaultedOptions = client().defaultQueryOptions(options());
|
|
@@ -74,23 +93,10 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
74
93
|
return observer.subscribe((result) => {
|
|
75
94
|
queryCore.notifyManager.batchCalls(() => {
|
|
76
95
|
const query = observer.getCurrentQuery();
|
|
77
|
-
const
|
|
78
|
-
const unwrappedResult = {
|
|
79
|
-
...rest,
|
|
80
|
-
// hydrate() expects a QueryState object, which is similar but not
|
|
81
|
-
// quite the same as a QueryObserverResult object. Thus, for now, we're
|
|
82
|
-
// copying over the missing properties from state in order to support hydration
|
|
83
|
-
dataUpdateCount: query.state.dataUpdateCount,
|
|
84
|
-
fetchFailureCount: query.state.fetchFailureCount,
|
|
85
|
-
// Removing these properties since they might not be serializable
|
|
86
|
-
// fetchFailureReason: query.state.fetchFailureReason,
|
|
87
|
-
// fetchMeta: query.state.fetchMeta,
|
|
88
|
-
isInvalidated: query.state.isInvalidated
|
|
89
|
-
};
|
|
96
|
+
const unwrappedResult = hydrateableObserverResult(query, result);
|
|
90
97
|
if (unwrappedResult.isError) {
|
|
91
98
|
reject(unwrappedResult.error);
|
|
92
|
-
}
|
|
93
|
-
if (unwrappedResult.isSuccess) {
|
|
99
|
+
} else {
|
|
94
100
|
resolve(unwrappedResult);
|
|
95
101
|
}
|
|
96
102
|
})();
|
|
@@ -134,7 +140,8 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
134
140
|
}
|
|
135
141
|
}
|
|
136
142
|
if (!state.isLoading) {
|
|
137
|
-
|
|
143
|
+
const query = observer.getCurrentQuery();
|
|
144
|
+
resolve(hydrateableObserverResult(query, state));
|
|
138
145
|
}
|
|
139
146
|
});
|
|
140
147
|
},
|
package/build/index.js
CHANGED
|
@@ -56,6 +56,25 @@ function reconcileFn(store, result, reconcileOption) {
|
|
|
56
56
|
const newData = reconcile(result.data, { key: reconcileOption })(store.data);
|
|
57
57
|
return { ...result, data: newData };
|
|
58
58
|
}
|
|
59
|
+
var hydrateableObserverResult = (query, result) => {
|
|
60
|
+
if (!isServer)
|
|
61
|
+
return result;
|
|
62
|
+
return {
|
|
63
|
+
...unwrap(result),
|
|
64
|
+
// cast to refetch function should be safe, since we only remove it on the server,
|
|
65
|
+
// and refetch is not relevant on the server
|
|
66
|
+
refetch: void 0,
|
|
67
|
+
// hydrate() expects a QueryState object, which is similar but not
|
|
68
|
+
// quite the same as a QueryObserverResult object. Thus, for now, we're
|
|
69
|
+
// copying over the missing properties from state in order to support hydration
|
|
70
|
+
dataUpdateCount: query.state.dataUpdateCount,
|
|
71
|
+
fetchFailureCount: query.state.fetchFailureCount,
|
|
72
|
+
isInvalidated: query.state.isInvalidated,
|
|
73
|
+
// Unsetting these properties on the server since they might not be serializable
|
|
74
|
+
fetchFailureReason: null,
|
|
75
|
+
fetchMeta: null
|
|
76
|
+
};
|
|
77
|
+
};
|
|
59
78
|
function createBaseQuery(options, Observer, queryClient) {
|
|
60
79
|
const client = createMemo(() => useQueryClient(queryClient?.()));
|
|
61
80
|
const defaultedOptions = client().defaultQueryOptions(options());
|
|
@@ -73,23 +92,10 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
73
92
|
return observer.subscribe((result) => {
|
|
74
93
|
notifyManager.batchCalls(() => {
|
|
75
94
|
const query = observer.getCurrentQuery();
|
|
76
|
-
const
|
|
77
|
-
const unwrappedResult = {
|
|
78
|
-
...rest,
|
|
79
|
-
// hydrate() expects a QueryState object, which is similar but not
|
|
80
|
-
// quite the same as a QueryObserverResult object. Thus, for now, we're
|
|
81
|
-
// copying over the missing properties from state in order to support hydration
|
|
82
|
-
dataUpdateCount: query.state.dataUpdateCount,
|
|
83
|
-
fetchFailureCount: query.state.fetchFailureCount,
|
|
84
|
-
// Removing these properties since they might not be serializable
|
|
85
|
-
// fetchFailureReason: query.state.fetchFailureReason,
|
|
86
|
-
// fetchMeta: query.state.fetchMeta,
|
|
87
|
-
isInvalidated: query.state.isInvalidated
|
|
88
|
-
};
|
|
95
|
+
const unwrappedResult = hydrateableObserverResult(query, result);
|
|
89
96
|
if (unwrappedResult.isError) {
|
|
90
97
|
reject(unwrappedResult.error);
|
|
91
|
-
}
|
|
92
|
-
if (unwrappedResult.isSuccess) {
|
|
98
|
+
} else {
|
|
93
99
|
resolve(unwrappedResult);
|
|
94
100
|
}
|
|
95
101
|
})();
|
|
@@ -133,7 +139,8 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
133
139
|
}
|
|
134
140
|
}
|
|
135
141
|
if (!state.isLoading) {
|
|
136
|
-
|
|
142
|
+
const query = observer.getCurrentQuery();
|
|
143
|
+
resolve(hydrateableObserverResult(query, state));
|
|
137
144
|
}
|
|
138
145
|
});
|
|
139
146
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/solid-query",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.4",
|
|
4
4
|
"description": "Primitives for managing, caching and syncing asynchronous and remote data in Solid",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -16,22 +16,24 @@
|
|
|
16
16
|
"types": "./build/index.d.ts",
|
|
17
17
|
"browser": {},
|
|
18
18
|
"exports": {
|
|
19
|
-
"solid": {
|
|
20
|
-
"development": "./build/dev.js",
|
|
21
|
-
"import": "./build/index.js"
|
|
22
|
-
},
|
|
23
19
|
"development": {
|
|
24
20
|
"import": {
|
|
25
21
|
"types": "./build/index.d.ts",
|
|
26
22
|
"default": "./build/dev.js"
|
|
27
23
|
},
|
|
28
|
-
"require":
|
|
24
|
+
"require": {
|
|
25
|
+
"types": "./build/index.d.cts",
|
|
26
|
+
"default": "./build/dev.cjs"
|
|
27
|
+
}
|
|
29
28
|
},
|
|
30
29
|
"import": {
|
|
31
30
|
"types": "./build/index.d.ts",
|
|
32
31
|
"default": "./build/index.js"
|
|
33
32
|
},
|
|
34
|
-
"require":
|
|
33
|
+
"require": {
|
|
34
|
+
"types": "./build/index.d.cts",
|
|
35
|
+
"default": "./build/index.cjs"
|
|
36
|
+
}
|
|
35
37
|
},
|
|
36
38
|
"sideEffects": [
|
|
37
39
|
"./src/setBatchUpdatesFn.ts"
|
|
@@ -41,21 +43,22 @@
|
|
|
41
43
|
"src"
|
|
42
44
|
],
|
|
43
45
|
"dependencies": {
|
|
46
|
+
"solid-js": "^1.7.8",
|
|
44
47
|
"@tanstack/query-core": "5.0.0-beta.0"
|
|
45
48
|
},
|
|
46
49
|
"devDependencies": {
|
|
47
|
-
"tsup-preset-solid": "^0.1
|
|
48
|
-
"vite-plugin-solid": "^2.
|
|
50
|
+
"tsup-preset-solid": "^2.0.1",
|
|
51
|
+
"vite-plugin-solid": "^2.7.0"
|
|
49
52
|
},
|
|
50
53
|
"peerDependencies": {
|
|
51
|
-
"solid-js": "^1.6.
|
|
54
|
+
"solid-js": "^1.6.0"
|
|
52
55
|
},
|
|
53
56
|
"scripts": {
|
|
54
57
|
"clean": "rimraf ./build && rimraf ./coverage",
|
|
55
58
|
"test:eslint": "eslint --ext .ts,.tsx ./src",
|
|
56
59
|
"test:types": "tsc",
|
|
57
60
|
"test:lib": "vitest run --coverage",
|
|
58
|
-
"test:lib:dev": "
|
|
61
|
+
"test:lib:dev": "vitest watch --coverage",
|
|
59
62
|
"test:build": "publint --strict",
|
|
60
63
|
"build": "tsup"
|
|
61
64
|
}
|
|
@@ -1452,7 +1452,7 @@ describe('createQuery', () => {
|
|
|
1452
1452
|
return (
|
|
1453
1453
|
<div>
|
|
1454
1454
|
<h1>
|
|
1455
|
-
data: {state.data}, count: {count}, isFetching:{' '}
|
|
1455
|
+
data: {state.data}, count: {count()}, isFetching:{' '}
|
|
1456
1456
|
{String(state.isFetching)}
|
|
1457
1457
|
</h1>
|
|
1458
1458
|
<button onClick={() => setCount(1)}>inc</button>
|
|
@@ -4265,7 +4265,7 @@ describe('createQuery', () => {
|
|
|
4265
4265
|
return (
|
|
4266
4266
|
<div>
|
|
4267
4267
|
<h2>Data: {JSON.stringify(state.data)}</h2>
|
|
4268
|
-
<h2>forceValue: {forceValue}</h2>
|
|
4268
|
+
<h2>forceValue: {forceValue()}</h2>
|
|
4269
4269
|
<button onClick={forceUpdate}>forceUpdate</button>
|
|
4270
4270
|
</div>
|
|
4271
4271
|
)
|
|
@@ -4320,7 +4320,7 @@ describe('createQuery', () => {
|
|
|
4320
4320
|
return (
|
|
4321
4321
|
<div>
|
|
4322
4322
|
<h2>Data: {JSON.stringify(state.data)}</h2>
|
|
4323
|
-
<h2>forceValue: {forceValue}</h2>
|
|
4323
|
+
<h2>forceValue: {forceValue()}</h2>
|
|
4324
4324
|
<button onClick={forceUpdate}>forceUpdate</button>
|
|
4325
4325
|
</div>
|
|
4326
4326
|
)
|
package/src/createBaseQuery.ts
CHANGED
|
@@ -18,9 +18,11 @@ import type { CreateBaseQueryOptions } from './types'
|
|
|
18
18
|
import type { Accessor } from 'solid-js'
|
|
19
19
|
import type { QueryClient } from './QueryClient'
|
|
20
20
|
import type {
|
|
21
|
+
Query,
|
|
21
22
|
QueryKey,
|
|
22
23
|
QueryObserver,
|
|
23
24
|
QueryObserverResult,
|
|
25
|
+
QueryState,
|
|
24
26
|
} from '@tanstack/query-core'
|
|
25
27
|
|
|
26
28
|
function reconcileFn<TData, TError>(
|
|
@@ -40,6 +42,49 @@ function reconcileFn<TData, TError>(
|
|
|
40
42
|
return { ...result, data: newData } as typeof result
|
|
41
43
|
}
|
|
42
44
|
|
|
45
|
+
type HydrateableQueryState<TData, TError> = QueryObserverResult<TData, TError> &
|
|
46
|
+
QueryState<TData, TError>
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Solid's `onHydrated` functionality will silently "fail" (hydrate with an empty object)
|
|
50
|
+
* if the resource data is not serializable.
|
|
51
|
+
*/
|
|
52
|
+
const hydrateableObserverResult = <
|
|
53
|
+
TQueryFnData,
|
|
54
|
+
TError,
|
|
55
|
+
TData,
|
|
56
|
+
TQueryKey extends QueryKey,
|
|
57
|
+
T2,
|
|
58
|
+
>(
|
|
59
|
+
query: Query<TQueryFnData, TError, TData, TQueryKey>,
|
|
60
|
+
result: QueryObserverResult<T2, TError>,
|
|
61
|
+
): HydrateableQueryState<T2, TError> => {
|
|
62
|
+
// Including the extra properties is only relevant on the server
|
|
63
|
+
if (!isServer) return result as HydrateableQueryState<T2, TError>
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
...unwrap(result),
|
|
67
|
+
|
|
68
|
+
// cast to refetch function should be safe, since we only remove it on the server,
|
|
69
|
+
// and refetch is not relevant on the server
|
|
70
|
+
refetch: undefined as unknown as HydrateableQueryState<
|
|
71
|
+
T2,
|
|
72
|
+
TError
|
|
73
|
+
>['refetch'],
|
|
74
|
+
|
|
75
|
+
// hydrate() expects a QueryState object, which is similar but not
|
|
76
|
+
// quite the same as a QueryObserverResult object. Thus, for now, we're
|
|
77
|
+
// copying over the missing properties from state in order to support hydration
|
|
78
|
+
dataUpdateCount: query.state.dataUpdateCount,
|
|
79
|
+
fetchFailureCount: query.state.fetchFailureCount,
|
|
80
|
+
isInvalidated: query.state.isInvalidated,
|
|
81
|
+
|
|
82
|
+
// Unsetting these properties on the server since they might not be serializable
|
|
83
|
+
fetchFailureReason: null,
|
|
84
|
+
fetchMeta: null,
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
43
88
|
// Base Query Function that is used to create the query.
|
|
44
89
|
export function createBaseQuery<
|
|
45
90
|
TQueryFnData,
|
|
@@ -54,6 +99,10 @@ export function createBaseQuery<
|
|
|
54
99
|
Observer: typeof QueryObserver,
|
|
55
100
|
queryClient?: Accessor<QueryClient>,
|
|
56
101
|
) {
|
|
102
|
+
type ResourceData =
|
|
103
|
+
| HydrateableQueryState<TData, TError>
|
|
104
|
+
| QueryObserverResult<TData, TError>
|
|
105
|
+
|
|
57
106
|
const client = createMemo(() => useQueryClient(queryClient?.()))
|
|
58
107
|
|
|
59
108
|
const defaultedOptions = client().defaultQueryOptions(options())
|
|
@@ -71,41 +120,19 @@ export function createBaseQuery<
|
|
|
71
120
|
|
|
72
121
|
const createServerSubscriber = (
|
|
73
122
|
resolve: (
|
|
74
|
-
data:
|
|
75
|
-
| QueryObserverResult<TData, TError>
|
|
76
|
-
| PromiseLike<QueryObserverResult<TData, TError> | undefined>
|
|
77
|
-
| undefined,
|
|
123
|
+
data: ResourceData | PromiseLike<ResourceData | undefined> | undefined,
|
|
78
124
|
) => void,
|
|
79
125
|
reject: (reason?: any) => void,
|
|
80
126
|
) => {
|
|
81
127
|
return observer.subscribe((result) => {
|
|
82
128
|
notifyManager.batchCalls(() => {
|
|
83
129
|
const query = observer.getCurrentQuery()
|
|
84
|
-
const
|
|
85
|
-
const unwrappedResult = {
|
|
86
|
-
...rest,
|
|
87
|
-
|
|
88
|
-
// hydrate() expects a QueryState object, which is similar but not
|
|
89
|
-
// quite the same as a QueryObserverResult object. Thus, for now, we're
|
|
90
|
-
// copying over the missing properties from state in order to support hydration
|
|
91
|
-
dataUpdateCount: query.state.dataUpdateCount,
|
|
92
|
-
fetchFailureCount: query.state.fetchFailureCount,
|
|
93
|
-
// Removing these properties since they might not be serializable
|
|
94
|
-
// fetchFailureReason: query.state.fetchFailureReason,
|
|
95
|
-
// fetchMeta: query.state.fetchMeta,
|
|
96
|
-
isInvalidated: query.state.isInvalidated,
|
|
97
|
-
}
|
|
130
|
+
const unwrappedResult = hydrateableObserverResult(query, result)
|
|
98
131
|
|
|
99
132
|
if (unwrappedResult.isError) {
|
|
100
|
-
if (process.env['NODE_ENV'] === 'development') {
|
|
101
|
-
console.error(unwrappedResult.error)
|
|
102
|
-
}
|
|
103
133
|
reject(unwrappedResult.error)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Use of any here is fine
|
|
107
|
-
// We cannot include refetch since it is not serializable
|
|
108
|
-
resolve(unwrappedResult as any)
|
|
134
|
+
} else {
|
|
135
|
+
resolve(unwrappedResult)
|
|
109
136
|
}
|
|
110
137
|
})()
|
|
111
138
|
})
|
|
@@ -148,7 +175,7 @@ export function createBaseQuery<
|
|
|
148
175
|
let unsubscribe: (() => void) | null = null
|
|
149
176
|
|
|
150
177
|
const [queryResource, { refetch, mutate }] = createResource<
|
|
151
|
-
|
|
178
|
+
ResourceData | undefined
|
|
152
179
|
>(
|
|
153
180
|
() => {
|
|
154
181
|
return new Promise((resolve, reject) => {
|
|
@@ -159,8 +186,10 @@ export function createBaseQuery<
|
|
|
159
186
|
unsubscribe = createClientSubscriber()
|
|
160
187
|
}
|
|
161
188
|
}
|
|
189
|
+
|
|
162
190
|
if (!state.isLoading) {
|
|
163
|
-
|
|
191
|
+
const query = observer.getCurrentQuery()
|
|
192
|
+
resolve(hydrateableObserverResult(query, state))
|
|
164
193
|
}
|
|
165
194
|
})
|
|
166
195
|
},
|