Skip to content

Commit a7b7c7d

Browse files
Merge branch 'alpha' into remove-overloads-codemod
2 parents 5af2a2e + 6c3b213 commit a7b7c7d

File tree

31 files changed

+90
-49
lines changed

31 files changed

+90
-49
lines changed

examples/react/algolia/src/SearchResults.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default function SearchResults({ query = "" }: SearchResultsProps) {
2424
query,
2525
hitsPerPage: 5,
2626
staleTime: 1000 * 30, // 30s
27-
cacheTime: 1000 * 60 * 15, // 15m
27+
gcTime: 1000 * 60 * 15, // 15m
2828
enabled: !!query,
2929
});
3030

examples/react/algolia/src/useAlgolia.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export type UseAlgoliaOptions = {
66
query: string;
77
hitsPerPage?: number;
88
staleTime?: number;
9-
cacheTime?: number;
9+
gcTime?: number;
1010
enabled?: boolean;
1111
};
1212

@@ -15,7 +15,7 @@ export default function useAlgolia<TData>({
1515
query,
1616
hitsPerPage = 10,
1717
staleTime,
18-
cacheTime,
18+
gcTime,
1919
enabled,
2020
}: UseAlgoliaOptions) {
2121
const queryInfo = useInfiniteQuery({
@@ -25,7 +25,7 @@ export default function useAlgolia<TData>({
2525
defaultPageParam: 0,
2626
getNextPageParam: (lastPage) => lastPage?.nextPage,
2727
staleTime,
28-
cacheTime,
28+
gcTime,
2929
enabled,
3030
});
3131

examples/react/basic-graphql-request/src/index.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function Posts({ setPostId }) {
7171
<div>
7272
<h1>Posts</h1>
7373
<div>
74-
{status === "loading" ? (
74+
{status === "pending" ? (
7575
"Loading..."
7676
) : status === "error" ? (
7777
<span>Error: {error.message}</span>
@@ -142,7 +142,7 @@ function Post({ postId, setPostId }) {
142142
Back
143143
</a>
144144
</div>
145-
{!postId || status === "loading" ? (
145+
{!postId || status === "pending" ? (
146146
"Loading..."
147147
) : status === "error" ? (
148148
<span>Error: {error.message}</span>

examples/react/basic-typescript/src/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function Posts({
4949
<div>
5050
<h1>Posts</h1>
5151
<div>
52-
{status === "loading" ? (
52+
{status === "pending" ? (
5353
"Loading..."
5454
) : error instanceof Error ? (
5555
<span>Error: {error.message}</span>
@@ -116,7 +116,7 @@ function Post({
116116
Back
117117
</a>
118118
</div>
119-
{!postId || status === "loading" ? (
119+
{!postId || status === "pending" ? (
120120
"Loading..."
121121
) : error instanceof Error ? (
122122
<span>Error: {error.message}</span>

examples/react/basic/src/index.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function Posts({ setPostId }) {
5757
<div>
5858
<h1>Posts</h1>
5959
<div>
60-
{status === "loading" ? (
60+
{status === "pending" ? (
6161
"Loading..."
6262
) : status === "error" ? (
6363
<span>Error: {error.message}</span>
@@ -118,7 +118,7 @@ function Post({ postId, setPostId }) {
118118
Back
119119
</a>
120120
</div>
121-
{!postId || status === "loading" ? (
121+
{!postId || status === "pending" ? (
122122
"Loading..."
123123
) : status === "error" ? (
124124
<span>Error: {error.message}</span>

examples/react/default-query-function/src/index.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function Posts({ setPostId }) {
6464
<div>
6565
<h1>Posts</h1>
6666
<div>
67-
{status === "loading" ? (
67+
{status === "pending" ? (
6868
"Loading..."
6969
) : status === "error" ? (
7070
<span>Error: {error.message}</span>
@@ -114,7 +114,7 @@ function Post({ postId, setPostId }) {
114114
Back
115115
</a>
116116
</div>
117-
{!postId || status === "loading" ? (
117+
{!postId || status === "pending" ? (
118118
"Loading..."
119119
) : status === "error" ? (
120120
<span>Error: {error.message}</span>

examples/react/playground/src/index.jsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ function Todos({ initialFilter = "", setEditingIndex }) {
189189
<input value={filter} onChange={(e) => setFilter(e.target.value)} />
190190
</label>
191191
</div>
192-
{status === "loading" ? (
192+
{status === "pending" ? (
193193
<span>Loading... (Attempt: {failureCount + 1})</span>
194194
) : status === "error" ? (
195195
<span>
@@ -260,7 +260,7 @@ function EditTodo({ editingIndex, setEditingIndex }) {
260260
};
261261

262262
const disableEditSave =
263-
status === "loading" || saveMutation.status === "loading";
263+
status === "pending" || saveMutation.status === "pending";
264264

265265
return (
266266
<div>
@@ -273,7 +273,7 @@ function EditTodo({ editingIndex, setEditingIndex }) {
273273
</>
274274
) : null}
275275
</div>
276-
{status === "loading" ? (
276+
{status === "pending" ? (
277277
<span>Loading... (Attempt: {failureCount + 1})</span>
278278
) : error ? (
279279
<span>
@@ -309,7 +309,7 @@ function EditTodo({ editingIndex, setEditingIndex }) {
309309
</button>
310310
</div>
311311
<div>
312-
{saveMutation.status === "loading"
312+
{saveMutation.status === "pending"
313313
? "Saving..."
314314
: saveMutation.status === "error"
315315
? saveMutation.error.message
@@ -346,18 +346,18 @@ function AddTodo() {
346346
<input
347347
value={name}
348348
onChange={(e) => setName(e.target.value)}
349-
disabled={addMutation.status === "loading"}
349+
disabled={addMutation.status === "pending"}
350350
/>
351351
<button
352352
onClick={() => {
353353
addMutation.mutate({ name });
354354
}}
355-
disabled={addMutation.status === "loading" || !name}
355+
disabled={addMutation.status === "pending" || !name}
356356
>
357357
Add Todo
358358
</button>
359359
<div>
360-
{addMutation.status === "loading"
360+
{addMutation.status === "pending"
361361
? "Saving..."
362362
: addMutation.status === "error"
363363
? addMutation.error.message

examples/react/rick-morty/src/Character.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function Character() {
2323
fetch(`https://rickandmortyapi.com/api/character/${characterId}`),
2424
});
2525

26-
if (status === "loading") return <p>Loading...</p>;
26+
if (status === "pending") return <p>Loading...</p>;
2727
if (status === "error") return <p>Error :(</p>;
2828

2929
const locationUrlPars = data.location.url.split("/").filter(Boolean);
@@ -105,7 +105,7 @@ function Location({ id }) {
105105
queryFn: () => fetch(`https://rickandmortyapi.com/api/location/${id}`),
106106
});
107107

108-
if (status === "loading") return <p>Loading...</p>;
108+
if (status === "pending") return <p>Loading...</p>;
109109
if (status === "error") return <p>Error :(</p>;
110110

111111
return (

examples/react/rick-morty/src/Characters.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default function Characters() {
1010
queryFn: () => fetch("https://rickandmortyapi.com/api/character/"),
1111
});
1212

13-
if (status === "loading") return <p>Loading...</p>;
13+
if (status === "pending") return <p>Loading...</p>;
1414
if (status === "error") return <p>Error :(</p>;
1515

1616
console.info(data);

examples/react/rick-morty/src/Episode.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function Episode() {
1313
fetch(`https://rickandmortyapi.com/api/episode/${episodeId}`),
1414
});
1515

16-
if (status === "loading") return <p>Loading...</p>;
16+
if (status === "pending") return <p>Loading...</p>;
1717
if (status === "error") return <p>Error :(</p>;
1818

1919
return (
@@ -37,7 +37,7 @@ function Character({ id }) {
3737
queryFn: () => fetch(`https://rickandmortyapi.com/api/character/${id}`),
3838
});
3939

40-
if (status === "loading") return <p>Loading...</p>;
40+
if (status === "pending") return <p>Loading...</p>;
4141
if (status === "error") return <p>Error :(</p>;
4242

4343
return (

examples/react/rick-morty/src/Episodes.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default function Episodes() {
1010
queryFn: () => fetch("https://rickandmortyapi.com/api/episode"),
1111
});
1212

13-
if (status === "loading") {
13+
if (status === "pending") {
1414
return <p>Loading...</p>;
1515
}
1616
if (status === "error") {

examples/react/star-wars/src/Character.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function Character(props) {
2222
queryFn: () => fetch(`https://swapi.dev/api/people/${characterId}/`),
2323
});
2424

25-
if (status === "loading") return <p>Loading...</p>;
25+
if (status === "pending") return <p>Loading...</p>;
2626
if (status === "error") return <p>Error :(</p>;
2727

2828
console.info({ data, status, error });

examples/react/star-wars/src/Characters.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default function Characters(props) {
1010
queryFn: () => fetch(`https://swapi.dev/api/people/`),
1111
});
1212

13-
if (status === "loading") return <p>Loading...</p>;
13+
if (status === "pending") return <p>Loading...</p>;
1414
if (status === "error") return <p>Error :(</p>;
1515

1616
return (

examples/react/star-wars/src/Film.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function Film(props) {
1212
queryFn: () => fetch(`https://swapi.dev/api/films/${filmId}/`),
1313
});
1414

15-
if (status === "loading") return <p>Loading...</p>;
15+
if (status === "pending") return <p>Loading...</p>;
1616
// this will not be necessary when v1 is released.
1717
if (data == null) {
1818
console.info("this shouldn't happen but it does 2");

examples/react/star-wars/src/Films.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default function Films(props) {
1010
queryFn: () => fetch("https://swapi.dev/api/films/"),
1111
});
1212

13-
if (status === "loading") {
13+
if (status === "pending") {
1414
return <p>Loading...</p>;
1515
}
1616
if (status === "error") {

examples/svelte/playground/src/lib/stores.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { writable } from 'svelte/store'
22

33
export const staleTime = writable(1000)
4-
export const cacheTime = writable(3000)
4+
export const gcTime = writable(3000)
55
export const errorRate = writable(0.05)
66
export const queryTimeMin = writable(1000)
77
export const queryTimeMax = writable(2000)

examples/svelte/playground/src/routes/+page.svelte

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { useQueryClient } from '@tanstack/svelte-query'
33
import {
44
staleTime,
5-
cacheTime,
5+
gcTime,
66
errorRate,
77
queryTimeMin,
88
queryTimeMax,
@@ -14,13 +14,13 @@
1414
queryClient.setDefaultOptions({
1515
queries: {
1616
staleTime: $staleTime,
17-
cacheTime: $cacheTime,
17+
gcTime: $gcTime,
1818
},
1919
})
2020
</script>
2121

2222
<p>
23-
The "staleTime" and "cacheTime" durations have been altered in this example to
23+
The "staleTime" and "gcTime" durations have been altered in this example to
2424
show how query stale-ness and query caching work on a granular level
2525
</p>
2626
<div>
@@ -34,12 +34,12 @@
3434
/>
3535
</div>
3636
<div>
37-
Cache Time:{' '}
37+
GcTime:{' '}
3838
<input
3939
type="number"
4040
min="0"
4141
step="1000"
42-
bind:value={$cacheTime}
42+
bind:value={$gcTime}
4343
style="width: 100px"
4444
/>
4545
</div>

packages/query-async-storage-persister/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tanstack/query-async-storage-persister",
3-
"version": "5.0.0-alpha.2",
3+
"version": "5.0.0-alpha.3",
44
"description": "A persister for asynchronous storages, to be used with TanStack/Query",
55
"author": "tannerlinsley",
66
"license": "MIT",

packages/query-broadcast-client-experimental/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tanstack/query-broadcast-client-experimental",
3-
"version": "5.0.0-alpha.2",
3+
"version": "5.0.0-alpha.3",
44
"description": "An experimental plugin to for broadcasting the state of your queryClient between browser tabs/windows",
55
"author": "tannerlinsley",
66
"license": "MIT",

packages/query-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tanstack/query-core",
3-
"version": "5.0.0-alpha.2",
3+
"version": "5.0.0-alpha.3",
44
"description": "The framework agnostic core that powers TanStack Query",
55
"author": "tannerlinsley",
66
"license": "MIT",

packages/query-core/src/mutation.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,26 +85,35 @@ export class Mutation<
8585
TContext = unknown,
8686
> extends Removable {
8787
state: MutationState<TData, TError, TVariables, TContext>
88-
readonly options: MutationOptions<TData, TError, TVariables, TContext>
88+
options!: MutationOptions<TData, TError, TVariables, TContext>
8989
readonly mutationId: number
9090

9191
#observers: MutationObserver<TData, TError, TVariables, TContext>[]
92+
#defaultOptions?: MutationOptions<TData, TError, TVariables, TContext>
9293
#mutationCache: MutationCache
9394
#retryer?: Retryer<TData>
9495

9596
constructor(config: MutationConfig<TData, TError, TVariables, TContext>) {
9697
super()
9798

98-
this.options = config.options
9999
this.mutationId = config.mutationId
100+
this.#defaultOptions = config.defaultOptions
100101
this.#mutationCache = config.mutationCache
101102
this.#observers = []
102103
this.state = config.state || getDefaultState()
103104

104-
this.updateGcTime(this.options.gcTime)
105+
this.setOptions(config.options)
105106
this.scheduleGc()
106107
}
107108

109+
setOptions(
110+
options?: MutationOptions<TData, TError, TVariables, TContext>,
111+
): void {
112+
this.options = { ...this.#defaultOptions, ...options }
113+
114+
this.updateGcTime(this.options.gcTime)
115+
}
116+
108117
get meta(): MutationMeta | undefined {
109118
return this.options.meta
110119
}

packages/query-core/src/mutationObserver.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export class MutationObserver<
6464
observer: this,
6565
})
6666
}
67+
this.#currentMutation?.setOptions(this.options)
6768
}
6869

6970
protected onUnsubscribe(): void {

0 commit comments

Comments
 (0)