Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: TanStack/query
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.45.1
Choose a base ref
...
head repository: TanStack/query
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v5.47.0
Choose a head ref
  • 18 commits
  • 164 files changed
  • 10 contributors

Commits on Jun 17, 2024

  1. ci: Update Nx and @tanstack/config (#7580)

    * ci: Update Nx and @tanstack/config
    
    * Undo prettier change
    lachlancollins authored Jun 17, 2024
    Copy the full SHA
    49795a3 View commit details

Commits on Jun 18, 2024

  1. docs(react-query): queryFn must be a function calling (#7572)

    * docs: queryFn must be a function calling
    
    * Update docs/framework/react/guides/advanced-ssr.md
    ndeitch authored Jun 18, 2024
    Copy the full SHA
    0ae229b View commit details

Commits on Jun 19, 2024

  1. chore: prettier

    TkDodo committed Jun 19, 2024
    Copy the full SHA
    bda8a54 View commit details

Commits on Jun 20, 2024

  1. chore(angular-query): prettier ignore api report (#7598)

    arnoud-dv authored Jun 20, 2024
    Copy the full SHA
    ad176cf View commit details
  2. docs(angular-query): angular zoneless support (#7600)

    arnoud-dv authored Jun 20, 2024
    Copy the full SHA
    89e1fbe View commit details

Commits on Jun 21, 2024

  1. feat(react-query-next-experimental): introduce nonce prop (#7575)

    allow the inline script to be executed when CSP is enforced by including nonce to the script
    
    Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
    hey-kevin and TkDodo authored Jun 21, 2024
    Copy the full SHA
    1c7739e View commit details
  2. release: v5.46.0

    tannerlinsley committed Jun 21, 2024
    Copy the full SHA
    a65b222 View commit details
  3. chore(svelte-query): Move tests folder (#7603)

    lachlancollins authored Jun 21, 2024
    Copy the full SHA
    ea26f26 View commit details
  4. refactor(angular-query): align inject-query and inject-infinite-query…

    … + clean-up create-base-query + add query correct type tests (#7593)
    Arthie authored Jun 21, 2024
    Copy the full SHA
    b7aaa03 View commit details
  5. release: v5.46.1

    tannerlinsley committed Jun 21, 2024
    Copy the full SHA
    62e2620 View commit details
  6. fix(angular-query): run mutation callback in injection context (#7360)

    * fix(angular-query-experimental): run mutation callback in injection context
    
    Previously, the injectMutation callback was run in injection context only if accessed in the same task as the component initialization (i.e. before the `effect` callback run). By running the effect run in injection context, it is ensured that the callback will always run in injection context, and any `inject` calls will not fail.
    
    Note there is a separate issue here, and it's that the callback is always run twice - once synchronously when initialization the mutation, and secondly as the first callback of the `effect`. This is something that can potentially be improved.
    
    No breaking changes, any code that worked before should still work.
    
    * run prettier
    
    * Catch error in test
    
    ---------
    
    Co-authored-by: Arnoud <6420061+arnoud-dv@users.noreply.github.com>
    ShacharHarshuv and arnoud-dv authored Jun 21, 2024
    Copy the full SHA
    cc47417 View commit details
  7. release: v5.46.2

    tannerlinsley committed Jun 21, 2024
    Copy the full SHA
    51d3e8f View commit details

Commits on Jun 22, 2024

  1. chore: Update typescript-eslint to v7 (#7610)

    * chore: Update typescript-eslint to v7
    
    * pnpm dedupe
    
    * Fix new errors
    lachlancollins authored Jun 22, 2024
    Copy the full SHA
    32bce35 View commit details

Commits on Jun 23, 2024

  1. ci: Add TS version tests (#7605)

    * Simplify implementation
    
    * Add to remaining packages
    lachlancollins authored Jun 23, 2024
    Copy the full SHA
    8253a80 View commit details

Commits on Jun 25, 2024

  1. ci: Add tests for TS 4.7, 4.8, 4.9 (#7618)

    * ci: Add tests for TS 4.7, 4.8, 4.9
    
    * Capitalise
    lachlancollins authored Jun 25, 2024
    Copy the full SHA
    15e42ba View commit details
  2. Copy the full SHA
    6355244 View commit details
  3. feat(react-query): usePrefetchQuery (#7582)

    * feat: usePrefetchQuery
    
    * refactor: switch to actual prefetching
    
    * refactor: remove ensureInfiniteQueryData function
    
    will do in a separate PR
    
    * chore: add tests for usePrefetchQuery and usePrefetchInfiniteQuery (#7586)
    
    * chore: add tests for usePrefetchQuery and usePrefetchInfiniteQuery
    
    * chore: update tests to assert the alternative spy is not called
    
    * chore: add some new tests
    
    * chore: remove it.only whoops
    
    * chore: call mockClear after fetching
    
    * chore: improve waterfall test by asserting fallback calls instead of loading node query
    
    * chore: improve code repetition
    
    * chore: add some generics to helper functions
    
    * usePrefetchQuery type tests and docs (#7592)
    
    * chore: add type tests and docs
    
    * chore: update hooks to use FetchQueryOptions and FetchInfiniteQueryOptions
    
    * chore: update tests
    
    * chore: update docs
    
    * chore: remove .md extension from link
    
    * chore: add unknown default value to TQueryFnData
    
    * Apply suggestions from code review
    
    ---------
    
    Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
    
    * Apply suggestions from code review
    
    Co-authored-by: Fredrik Höglund <fredrik.hoglund@gmail.com>
    
    * chore: fix types in tests
    
    * chore: add new tests (#7614)
    
    * chore: add new tests
    
    * Apply suggestions from code review
    
    ---------
    
    Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
    
    ---------
    
    Co-authored-by: Bruno Lopes <88719327+brunolopesr@users.noreply.github.com>
    Co-authored-by: Fredrik Höglund <fredrik.hoglund@gmail.com>
    3 people authored Jun 25, 2024
    Copy the full SHA
    fbfe940 View commit details
  4. release: v5.47.0

    tannerlinsley committed Jun 25, 2024
    Copy the full SHA
    461f3af View commit details
Showing with 2,986 additions and 2,553 deletions.
  1. +2 −0 .github/workflows/ci.yml
  2. +2 −0 .github/workflows/pr.yml
  3. +1 −0 .gitignore
  4. +3 −0 .prettierignore
  5. +12 −0 docs/config.json
  6. +11 −0 docs/framework/angular/zoneless.md
  7. +6 −1 docs/framework/react/guides/advanced-ssr.md
  8. +30 −33 docs/framework/react/guides/prefetching.md
  9. +37 −0 docs/framework/react/reference/usePrefetchInfiniteQuery.md
  10. +24 −0 docs/framework/react/reference/usePrefetchQuery.md
  11. +2 −2 examples/angular/basic/package.json
  12. +2 −2 examples/angular/infinite-query-with-max-pages/package.json
  13. +2 −2 examples/angular/router/package.json
  14. +2 −2 examples/angular/simple/package.json
  15. +3 −3 examples/react/algolia/package.json
  16. +1 −1 examples/react/algolia/tsconfig.json
  17. +2 −2 examples/react/auto-refetching/package.json
  18. +2 −2 examples/react/basic-graphql-request/package.json
  19. +6 −6 examples/react/basic-typescript/package.json
  20. +1 −1 examples/react/basic-typescript/tsconfig.json
  21. +3 −3 examples/react/basic/package.json
  22. +2 −2 examples/react/default-query-function/package.json
  23. +2 −2 examples/react/infinite-query-with-max-pages/package.json
  24. +2 −2 examples/react/load-more-infinite-scroll/package.json
  25. +2 −2 examples/react/nextjs-app-prefetching/package.json
  26. +1 −1 examples/react/nextjs-app-prefetching/tsconfig.json
  27. +3 −3 examples/react/nextjs-suspense-streaming/package.json
  28. +2 −2 examples/react/nextjs/package.json
  29. +4 −4 examples/react/offline/package.json
  30. +2 −2 examples/react/optimistic-updates-cache/package.json
  31. +2 −2 examples/react/optimistic-updates-ui/package.json
  32. +2 −2 examples/react/pagination/package.json
  33. +2 −2 examples/react/playground/package.json
  34. +2 −2 examples/react/prefetching/package.json
  35. +2 −2 examples/react/react-native/package.json
  36. +2 −2 examples/react/react-router/package.json
  37. +1 −1 examples/react/react-router/tsconfig.json
  38. +2 −2 examples/react/rick-morty/package.json
  39. +3 −3 examples/react/shadow-dom/package.json
  40. +1 −1 examples/react/shadow-dom/tsconfig.json
  41. +1 −1 examples/react/shadow-dom/tsconfig.node.json
  42. +2 −2 examples/react/simple/package.json
  43. +2 −2 examples/react/star-wars/package.json
  44. +2 −2 examples/react/suspense/package.json
  45. +2 −2 examples/solid/astro/package.json
  46. +2 −2 examples/solid/basic-graphql-request/package.json
  47. +1 −1 examples/solid/basic-graphql-request/tsconfig.json
  48. +2 −2 examples/solid/basic-typescript/package.json
  49. +1 −1 examples/solid/basic-typescript/tsconfig.json
  50. +2 −2 examples/solid/default-query-function/package.json
  51. +1 −1 examples/solid/default-query-function/tsconfig.json
  52. +3 −3 examples/solid/simple/package.json
  53. +1 −1 examples/solid/simple/tsconfig.json
  54. +2 −2 examples/solid/solid-start-streaming/package.json
  55. +2 −2 examples/svelte/auto-refetching/package.json
  56. +2 −2 examples/svelte/basic/package.json
  57. +2 −2 examples/svelte/load-more-infinite-scroll/package.json
  58. +2 −2 examples/svelte/optimistic-updates-typescript/package.json
  59. +2 −2 examples/svelte/playground/package.json
  60. +2 −2 examples/svelte/simple/package.json
  61. +2 −2 examples/svelte/ssr/package.json
  62. +2 −2 examples/svelte/star-wars/package.json
  63. +1 −1 examples/vue/2.6-basic/package.json
  64. +1 −1 examples/vue/2.7-basic/package.json
  65. +2 −2 examples/vue/basic/package.json
  66. +1 −1 examples/vue/dependent-queries/package.json
  67. +1 −1 examples/vue/nuxt3/package.json
  68. +4 −4 examples/vue/persister/package.json
  69. +2 −2 examples/vue/simple/package.json
  70. +1 −1 integrations/react-next-15/tsconfig.json
  71. +1 −1 integrations/react-next/tsconfig.json
  72. +1 −1 integrations/vue-vite/tsconfig.json
  73. +1 −1 integrations/vue-vite/tsconfig.node.json
  74. +14 −8 package.json
  75. +6 −3 packages/angular-query-devtools-experimental/package.json
  76. +3 −3 packages/angular-query-devtools-experimental/tsconfig.build.json
  77. +7 −19 packages/angular-query-devtools-experimental/tsconfig.json
  78. +0 −2 packages/angular-query-experimental/.prettierignore
  79. +0 −1 packages/angular-query-experimental/etc/angular-query-experimental.api.md
  80. +7 −3 packages/angular-query-experimental/package.json
  81. +1 −3 packages/angular-query-experimental/src/__tests__/inject-infinite-query.test.ts
  82. +6 −4 packages/angular-query-experimental/src/__tests__/inject-is-fetching.test.ts
  83. +6 −4 packages/angular-query-experimental/src/__tests__/inject-is-mutating.test.ts
  84. +2 −2 packages/angular-query-experimental/src/__tests__/inject-mutation-state.test-d.ts
  85. +6 −4 packages/angular-query-experimental/src/__tests__/inject-mutation-state.test.ts
  86. +1 −1 packages/angular-query-experimental/src/__tests__/inject-mutation.test-d.ts
  87. +43 −4 packages/angular-query-experimental/src/__tests__/inject-mutation.test.ts
  88. +1 −1 packages/angular-query-experimental/src/__tests__/inject-query.test-d.ts
  89. +278 −6 packages/angular-query-experimental/src/__tests__/inject-query.test.ts
  90. +1 −4 packages/angular-query-experimental/src/__tests__/query-options.test-d.ts
  91. +6 −0 packages/angular-query-experimental/src/__tests__/test-utils.ts
  92. +57 −54 packages/angular-query-experimental/src/create-base-query.ts
  93. +3 −9 packages/angular-query-experimental/src/inject-infinite-query.ts
  94. +5 −1 packages/angular-query-experimental/src/inject-mutation.ts
  95. +4 −13 packages/angular-query-experimental/src/inject-query.ts
  96. +3 −3 packages/angular-query-experimental/tsconfig.build.json
  97. +7 −18 packages/angular-query-experimental/tsconfig.json
  98. +9 −5 packages/eslint-plugin-query/package.json
  99. +4 −1 packages/eslint-plugin-query/tsconfig.json
  100. +6 −2 packages/query-async-storage-persister/package.json
  101. +4 −7 packages/query-async-storage-persister/tsconfig.json
  102. +6 −2 packages/query-broadcast-client-experimental/package.json
  103. +4 −1 packages/query-broadcast-client-experimental/tsconfig.json
  104. +4 −1 packages/query-codemods/tsconfig.json
  105. +9 −2 packages/query-core/package.json
  106. +1 −1 packages/query-core/src/__tests__/queryClient.test-d.tsx
  107. +4 −7 packages/query-core/tsconfig.json
  108. +5 −0 packages/query-core/tsconfig.legacy.json
  109. +6 −2 packages/query-devtools/package.json
  110. +3 −8 packages/query-devtools/tsconfig.json
  111. +6 −2 packages/query-persist-client-core/package.json
  112. +4 −7 packages/query-persist-client-core/tsconfig.json
  113. +6 −2 packages/query-sync-storage-persister/package.json
  114. +4 −7 packages/query-sync-storage-persister/tsconfig.json
  115. +6 −2 packages/react-query-devtools/package.json
  116. +3 −3 packages/react-query-devtools/tsconfig.json
  117. +6 −2 packages/react-query-next-experimental/package.json
  118. +9 −0 packages/react-query-next-experimental/src/HydrationStreamProvider.tsx
  119. +2 −0 packages/react-query-next-experimental/src/ReactQueryStreamedHydration.tsx
  120. +3 −8 packages/react-query-next-experimental/tsconfig.json
  121. +6 −2 packages/react-query-persist-client/package.json
  122. +3 −3 packages/react-query-persist-client/tsconfig.json
  123. +9 −2 packages/react-query/package.json
  124. +80 −0 packages/react-query/src/__tests__/prefetch.test-d.tsx
  125. +434 −0 packages/react-query/src/__tests__/prefetch.test.tsx
  126. +1 −0 packages/react-query/src/index.ts
  127. +42 −0 packages/react-query/src/prefetch.ts
  128. +3 −3 packages/react-query/tsconfig.json
  129. +8 −0 packages/react-query/tsconfig.legacy.json
  130. +6 −2 packages/solid-query-devtools/package.json
  131. +3 −8 packages/solid-query-devtools/tsconfig.json
  132. +6 −2 packages/solid-query-persist-client/package.json
  133. +3 −3 packages/solid-query-persist-client/tsconfig.json
  134. +7 −2 packages/solid-query/package.json
  135. +3 −3 packages/solid-query/tsconfig.json
  136. +9 −0 packages/solid-query/tsconfig.legacy.json
  137. +3 −3 packages/svelte-query-devtools/package.json
  138. +3 −0 packages/svelte-query-devtools/tsconfig.json
  139. +3 −3 packages/svelte-query-persist-client/package.json
  140. +3 −0 packages/svelte-query-persist-client/tsconfig.json
  141. +4 −6 packages/svelte-query/package.json
  142. +3 −3 packages/svelte-query/{src/__tests__ → tests}/CreateMutation.svelte
  143. +2 −2 packages/svelte-query/{src/__tests__ → tests}/CreateQueries.svelte
  144. +2 −2 packages/svelte-query/{src/__tests__ → tests}/CreateQuery.svelte
  145. +7 −5 packages/svelte-query/{src/__tests__ → tests}/UseMutationState.svelte
  146. +1 −1 packages/svelte-query/{src/__tests__ → tests}/context.test.ts
  147. 0 packages/svelte-query/{src/__tests__ → tests}/createMutation.test.ts
  148. 0 packages/svelte-query/{src/__tests__ → tests}/createQueries.test.ts
  149. 0 packages/svelte-query/{src/__tests__ → tests}/createQuery.test.ts
  150. +1 −1 packages/svelte-query/{src/__tests__ → tests}/queryOptions.test.ts
  151. 0 packages/svelte-query/{ → tests}/test-setup.ts
  152. 0 packages/svelte-query/{src/__tests__ → tests}/useMutationState.test.ts
  153. 0 packages/svelte-query/{src/__tests__ → tests}/utils.ts
  154. +6 −1 packages/svelte-query/tsconfig.json
  155. +2 −2 packages/svelte-query/vite.config.ts
  156. +1 −1 packages/vue-query-devtools/package.json
  157. +3 −0 packages/vue-query-devtools/tsconfig.json
  158. +13 −6 packages/vue-query/package.json
  159. +1 −1 packages/vue-query/src/__tests__/queryClient.test-d.ts
  160. +4 −2 packages/vue-query/tsconfig.json
  161. +5 −0 packages/vue-query/tsconfig.legacy.json
  162. +1,457 −2,085 pnpm-lock.yaml
  163. +7 −0 scripts/tsconfig.json
  164. +2 −2 tsconfig.json
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -56,5 +56,7 @@ jobs:
TAG: ${{ inputs.tag }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
directory: packages
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2 changes: 2 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -43,5 +43,7 @@ jobs:
run: npx nx-cloud stop-all-agents
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
directory: packages
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@ stats.html
.cache
.idea
.nx/cache
.nx/workspace-data
.pnpm-store
.svelte-kit
.tsup
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -8,3 +8,6 @@
pnpm-lock.yaml
packages/**/tsup.config.bundled*.mjs
**/tsconfig.vitest-temp.json

# API Extractor report
packages/angular-query-experimental/etc/*.md
12 changes: 12 additions & 0 deletions docs/config.json
Original file line number Diff line number Diff line change
@@ -144,6 +144,10 @@
{
"label": "Devtools",
"to": "framework/angular/devtools"
},
{
"label": "Zoneless",
"to": "framework/angular/zoneless"
}
]
}
@@ -654,6 +658,14 @@
"label": "infiniteQueryOptions",
"to": "framework/react/reference/infiniteQueryOptions"
},
{
"label": "usePrefetchQuery",
"to": "framework/react/reference/usePrefetchQuery"
},
{
"label": "usePrefetchInfiniteQuery",
"to": "framework/react/reference/usePrefetchInfiniteQuery"
},
{
"label": "QueryErrorResetBoundary",
"to": "framework/react/reference/QueryErrorResetBoundary"
11 changes: 11 additions & 0 deletions docs/framework/angular/zoneless.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
id: zoneless
title: Zoneless Angular
---

Because the Angular adapter for TanStack Query is built on signals, it fully supports Zoneless!

Among Zoneless benefits are improved performance and debugging experience. For details see the [Angular documentation](https://angular.dev/guide/experimental/zoneless).

> Keep in mind that the API for Angular Zoneless is currently experimental and can change in Angular patch versions.
> Besides Zoneless, ZoneJS change detection is also fully supported.
7 changes: 6 additions & 1 deletion docs/framework/react/guides/advanced-ssr.md
Original file line number Diff line number Diff line change
@@ -192,7 +192,10 @@ Next, we'll look at what the Client Component part looks like:
export default function Posts() {
// This useQuery could just as well happen in some deeper
// child to <Posts>, data will be available immediately either way
const { data } = useQuery({ queryKey: ['posts'], queryFn: getPosts })
const { data } = useQuery({
queryKey: ['posts'],
queryFn: () => getPosts(),
})

// This query was not prefetched on the server and will not start
// fetching until on the client, both patterns are fine to mix.
@@ -211,6 +214,8 @@ In the SSR guide, we noted that you could get rid of the boilerplate of having `

> NOTE: If you encounter a type error while using async Server Components with TypeScript versions lower than `5.1.3` and `@types/react` versions lower than `18.2.8`, it is recommended to update to the latest versions of both. Alternatively, you can use the temporary workaround of adding `{/* @ts-expect-error Server Component */}` when calling this component inside another. For more information, see [Async Server Component TypeScript Error](https://nextjs.org/docs/app/building-your-application/configuring/typescript#async-server-component-typescript-error) in the Next.js 13 docs.
> NOTE: If you encounter an error `Only plain objects, and a few built-ins, can be passed to Server Actions. Classes or null prototypes are not supported.` make sure that you're **not** passing to queryFn a function reference, instead call the function because queryFn args has a bunch of properties and not all of it would be serializable. see [Server Action only works when queryFn isn't a reference](https://github.com/TanStack/query/issues/6264).
### Nesting Server Components

A nice thing about Server Components is that they can be nested and exist on many levels in the React tree, making it possible to prefetch data closer to where it's actually used instead of only at the top of the application (just like Remix loaders). This can be as simple as a Server Component rendering another Server Component (we'll leave the Client Components out in this example for brevity):
63 changes: 30 additions & 33 deletions docs/framework/react/guides/prefetching.md
Original file line number Diff line number Diff line change
@@ -196,45 +196,41 @@ This starts fetching `'article-comments'` immediately and flattens the waterfall

[//]: # 'Suspense'

If you want to prefetch together with Suspense, you will have to do things a bit differently. You can't use `useSuspenseQueries` to prefetch, since the prefetch would block the component from rendering. You also can not use `useQuery` for the prefetch, because that wouldn't start the prefetch until after suspenseful query had resolved. What you can do is add a small `usePrefetchQuery` function (we might add this to the library itself at a later point):

```tsx
function usePrefetchQuery(options) {
const queryClient = useQueryClient()

// This happens in render, but is safe to do because ensureQueryData
// only fetches if there is no data in the cache for this query. This
// means we know no observers are watching the data so the side effect
// is not observable, which is safe.
if (!queryClient.getQueryState(options.queryKey)) {
queryClient.ensureQueryData(options).catch(() => {
// Avoid uncaught error
})
}
}
```

This approach works with both `useQuery` and `useSuspenseQuery`, so feel free to use it as an alternative to the `useQuery({ ..., notifyOnChangeProps: [] })` approach as well. The only tradeoff is that the above function will never fetch and _update_ existing data in the cache if it's stale, but this will usually happen in the later query anyway.
If you want to prefetch together with Suspense, you will have to do things a bit differently. You can't use `useSuspenseQueries` to prefetch, since the prefetch would block the component from rendering. You also can not use `useQuery` for the prefetch, because that wouldn't start the prefetch until after suspenseful query had resolved. For this scenario, you can use the [`usePrefetchQuery`](../reference/usePrefetchQuery) or the [`usePrefetchInfiniteQuery`](../reference/usePrefetchInfiniteQuery) hooks available in the library.

You can now use `useSuspenseQuery` in the component that actually needs the data. You _might_ want to wrap this later component in its own `<Suspense>` boundary so the "secondary" query we are prefetching does not block rendering of the "primary" data.

```tsx
// Prefetch
usePrefetchQuery({
queryKey: ['article-comments', id],
queryFn: getArticleCommentsById,
})
function App() {
usePrefetchQuery({
queryKey: ['articles'],
queryFn: (...args) => {
return getArticles(...args)
},
})

const { data: articleResult } = useSuspenseQuery({
queryKey: ['article', id],
queryFn: getArticleById,
})
return (
<Suspense fallback="Loading articles...">
<Articles />
</Suspense>
)
}

// In nested component:
const { data: commentsResult } = useSuspenseQuery({
queryKey: ['article-comments', id],
queryFn: getArticleCommentsById,
})
function Articles() {
const { data: articles } = useSuspenseQuery({
queryKey: ['articles'],
queryFn: (...args) => {
return getArticles(...args)
},
})

return articles.map((article) => (
<div key={articleData.id}>
<ArticleHeader article={article} />
<ArticleBody article={article} />
</div>
))
}
```

Another way is to prefetch inside of the query function. This makes sense if you know that every time an article is fetched it's very likely comments will also be needed. For this, we'll use `queryClient.prefetchQuery`:
@@ -269,6 +265,7 @@ useEffect(() => {

To recap, if you want to prefetch a query during the component lifecycle, there are a few different ways to do it, pick the one that suits your situation best:

- Prefetch before a suspense boundary using `usePrefetchQuery` or `usePrefetchInfiniteQuery` hooks
- Use `useQuery` or `useSuspenseQueries` and ignore the result
- Prefetch inside the query function
- Prefetch in an effect
37 changes: 37 additions & 0 deletions docs/framework/react/reference/usePrefetchInfiniteQuery.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
id: usePrefetchInfiniteQuery
title: usePrefetchInfiniteQuery
---

```tsx
const result = usePrefetchInfiniteQuery(options)
```

**Options**

You can pass everything to `usePrefetchInfiniteQuery` that you can pass to [`queryClient.prefetchInfiniteQuery`](../../../reference/QueryClient#queryclientprefetchinfinitequery). Remember that some of them are required as below:

- `queryKey: QueryKey`

- **Required**
- The query key to prefetch during render

- `queryFn: (context: QueryFunctionContext) => Promise<TData>`

- **Required, but only if no default query function has been defined** See [Default Query Function](../../guides/default-query-function) for more information.

- `initialPageParam: TPageParam`

- **Required**
- The default page param to use when fetching the first page.

- `getNextPageParam: (lastPage, allPages, lastPageParam, allPageParams) => TPageParam | undefined | null`

- **Required**
- When new data is received for this query, this function receives both the last page of the infinite list of data and the full array of all pages, as well as pageParam information.
- It should return a **single variable** that will be passed as the last optional parameter to your query function.
- Return `undefined` or `null` to indicate there is no next page available.

- **Returns**

The `usePrefetchInfiniteQuery` does not return anything, it should be used just to fire a prefetch during render, before a suspense boundary that wraps a component that uses [`useSuspenseInfiniteQuery`](../reference/useSuspenseInfiniteQuery)
24 changes: 24 additions & 0 deletions docs/framework/react/reference/usePrefetchQuery.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
id: usePrefetchQuery
title: usePrefetchQuery
---

```tsx
const result = usePrefetchQuery(options)
```

**Options**

You can pass everything to `usePrefetchQuery` that you can pass to [`queryClient.prefetchQuery`](../../../reference/QueryClient#queryclientprefetchquery). Remember that some of them are required as below:

- `queryKey: QueryKey`

- **Required**
- The query key to prefetch during render

- `queryFn: (context: QueryFunctionContext) => Promise<TData>`
- **Required, but only if no default query function has been defined** See [Default Query Function](../../guides/default-query-function) for more information.

**Returns**

The `usePrefetchQuery` does not return anything, it should be used just to fire a prefetch during render, before a suspense boundary that wraps a component that uses [`useSuspenseQuery`](../reference/useSuspenseQuery).
4 changes: 2 additions & 2 deletions examples/angular/basic/package.json
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
"@angular/core": "^17.3.10",
"@angular/platform-browser": "^17.3.10",
"@angular/platform-browser-dynamic": "^17.3.10",
"@tanstack/angular-query-experimental": "^5.45.0",
"@tanstack/angular-query-experimental": "^5.47.0",
"rxjs": "^7.8.1",
"tslib": "^2.6.2",
"zone.js": "^0.14.6"
@@ -23,7 +23,7 @@
"@angular-devkit/build-angular": "^17.3.8",
"@angular/cli": "^17.3.8",
"@angular/compiler-cli": "^17.3.10",
"@tanstack/angular-query-devtools-experimental": "^5.45.0",
"@tanstack/angular-query-devtools-experimental": "^5.47.0",
"typescript": "5.3.3"
}
}
4 changes: 2 additions & 2 deletions examples/angular/infinite-query-with-max-pages/package.json
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
"@angular/core": "^17.3.10",
"@angular/platform-browser": "^17.3.10",
"@angular/platform-browser-dynamic": "^17.3.10",
"@tanstack/angular-query-experimental": "^5.45.0",
"@tanstack/angular-query-experimental": "^5.47.0",
"rxjs": "^7.8.1",
"tslib": "^2.6.2",
"zone.js": "^0.14.6"
@@ -23,7 +23,7 @@
"@angular-devkit/build-angular": "^17.3.8",
"@angular/cli": "^17.3.8",
"@angular/compiler-cli": "^17.3.10",
"@tanstack/angular-query-devtools-experimental": "^5.45.0",
"@tanstack/angular-query-devtools-experimental": "^5.47.0",
"typescript": "5.3.3"
}
}
4 changes: 2 additions & 2 deletions examples/angular/router/package.json
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
"@angular/platform-browser": "^17.3.10",
"@angular/platform-browser-dynamic": "^17.3.10",
"@angular/router": "^17.3.10",
"@tanstack/angular-query-experimental": "^5.45.0",
"@tanstack/angular-query-experimental": "^5.47.0",
"rxjs": "^7.8.1",
"tslib": "^2.6.2",
"zone.js": "^0.14.6"
@@ -24,7 +24,7 @@
"@angular-devkit/build-angular": "^17.3.8",
"@angular/cli": "^17.3.8",
"@angular/compiler-cli": "^17.3.10",
"@tanstack/angular-query-devtools-experimental": "^5.45.0",
"@tanstack/angular-query-devtools-experimental": "^5.47.0",
"typescript": "5.3.3"
}
}
4 changes: 2 additions & 2 deletions examples/angular/simple/package.json
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
"@angular/platform-browser": "^17.3.10",
"@angular/platform-browser-dynamic": "^17.3.10",
"@angular/router": "^17.3.10",
"@tanstack/angular-query-experimental": "^5.45.0",
"@tanstack/angular-query-experimental": "^5.47.0",
"rxjs": "^7.8.1",
"tslib": "^2.6.2",
"zone.js": "^0.14.6"
@@ -24,7 +24,7 @@
"@angular-devkit/build-angular": "^17.3.8",
"@angular/cli": "^17.3.8",
"@angular/compiler-cli": "^17.3.10",
"@tanstack/angular-query-devtools-experimental": "^5.45.0",
"@tanstack/angular-query-devtools-experimental": "^5.47.0",
"typescript": "5.3.3"
}
}
6 changes: 3 additions & 3 deletions examples/react/algolia/package.json
Original file line number Diff line number Diff line change
@@ -11,14 +11,14 @@
"dependencies": {
"@algolia/client-search": "4.23.3",
"@algolia/transporter": "4.23.3",
"@tanstack/react-query": "^5.45.1",
"@tanstack/react-query-devtools": "^5.45.1",
"@tanstack/react-query": "^5.47.0",
"@tanstack/react-query-devtools": "^5.47.0",
"algoliasearch": "4.23.3",
"react": "19.0.0-rc-4c2e457c7c-20240522",
"react-dom": "19.0.0-rc-4c2e457c7c-20240522"
},
"devDependencies": {
"@tanstack/eslint-plugin-query": "^5.43.1",
"@tanstack/eslint-plugin-query": "^5.47.0",
"@types/react": "^18.2.79",
"@types/react-dom": "^18.2.25",
"@vitejs/plugin-react": "^4.2.1",
2 changes: 1 addition & 1 deletion examples/react/algolia/tsconfig.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"moduleResolution": "Bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
4 changes: 2 additions & 2 deletions examples/react/auto-refetching/package.json
Original file line number Diff line number Diff line change
@@ -7,8 +7,8 @@
"start": "next start"
},
"dependencies": {
"@tanstack/react-query": "^5.45.1",
"@tanstack/react-query-devtools": "^5.45.1",
"@tanstack/react-query": "^5.47.0",
"@tanstack/react-query-devtools": "^5.47.0",
"axios": "^1.6.8",
"isomorphic-unfetch": "4.0.2",
"next": "^14.0.0",
4 changes: 2 additions & 2 deletions examples/react/basic-graphql-request/package.json
Original file line number Diff line number Diff line change
@@ -8,8 +8,8 @@
"preview": "vite preview"
},
"dependencies": {
"@tanstack/react-query": "^5.45.1",
"@tanstack/react-query-devtools": "^5.45.1",
"@tanstack/react-query": "^5.47.0",
"@tanstack/react-query-devtools": "^5.47.0",
"graphql": "^16.8.1",
"graphql-request": "^7.0.1",
"react": "19.0.0-rc-4c2e457c7c-20240522",
12 changes: 6 additions & 6 deletions examples/react/basic-typescript/package.json
Original file line number Diff line number Diff line change
@@ -9,20 +9,20 @@
"test:types": "tsc"
},
"dependencies": {
"@tanstack/query-sync-storage-persister": "^5.45.0",
"@tanstack/react-query": "^5.45.1",
"@tanstack/react-query-devtools": "^5.45.1",
"@tanstack/react-query-persist-client": "^5.45.1",
"@tanstack/query-sync-storage-persister": "^5.47.0",
"@tanstack/react-query": "^5.47.0",
"@tanstack/react-query-devtools": "^5.47.0",
"@tanstack/react-query-persist-client": "^5.47.0",
"axios": "^1.6.8",
"react": "19.0.0-rc-4c2e457c7c-20240522",
"react-dom": "19.0.0-rc-4c2e457c7c-20240522"
},
"devDependencies": {
"@tanstack/eslint-plugin-query": "^5.43.1",
"@tanstack/eslint-plugin-query": "^5.47.0",
"@types/react": "^18.2.79",
"@types/react-dom": "^18.2.25",
"@vitejs/plugin-react": "^4.2.1",
"eslint": "^8.56.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"typescript": "5.3.3",
"vite": "^5.2.11"
2 changes: 1 addition & 1 deletion examples/react/basic-typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"moduleResolution": "Bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
Loading