Skip to content

feat: add support for React.use() - #7988

Merged
TkDodo merged 115 commits into
TanStack:mainfrom
KATT:discussions-7980-promises
Oct 1, 2024
Merged

feat: add support for React.use()#7988
TkDodo merged 115 commits into
TanStack:mainfrom
KATT:discussions-7980-promises

Conversation

@KATT

@KATT KATT commented Aug 30, 2024

Copy link
Copy Markdown
Contributor

Closes #7980


Progress

  • add basic functionality for useQuery()
  • make other tests pass (👋 help wanted!)
  • add test for useInfiniteQuery()
  • do more tests with some example
  • update docs?

@nx-cloud

nx-cloud Bot commented Aug 30, 2024

Copy link
Copy Markdown

☁️ Nx Cloud Report

CI is running/has finished running commands for commit cb0dfb4. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 2 targets

Sent with 💌 from NxCloud.

@pkg-pr-new

pkg-pr-new Bot commented Aug 30, 2024

Copy link
Copy Markdown

Open in Stackblitz

More templates

@tanstack/angular-query-devtools-experimental

pnpm add https://pkg.pr.new/@tanstack/angular-query-devtools-experimental@7988

@tanstack/eslint-plugin-query

pnpm add https://pkg.pr.new/@tanstack/eslint-plugin-query@7988

@tanstack/angular-query-experimental

pnpm add https://pkg.pr.new/@tanstack/angular-query-experimental@7988

@tanstack/query-async-storage-persister

pnpm add https://pkg.pr.new/@tanstack/query-async-storage-persister@7988

@tanstack/query-broadcast-client-experimental

pnpm add https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@7988

@tanstack/query-devtools

pnpm add https://pkg.pr.new/@tanstack/query-devtools@7988

@tanstack/query-core

pnpm add https://pkg.pr.new/@tanstack/query-core@7988

@tanstack/query-persist-client-core

pnpm add https://pkg.pr.new/@tanstack/query-persist-client-core@7988

@tanstack/query-sync-storage-persister

pnpm add https://pkg.pr.new/@tanstack/query-sync-storage-persister@7988

@tanstack/react-query

pnpm add https://pkg.pr.new/@tanstack/react-query@7988

@tanstack/react-query-devtools

pnpm add https://pkg.pr.new/@tanstack/react-query-devtools@7988

@tanstack/react-query-next-experimental

pnpm add https://pkg.pr.new/@tanstack/react-query-next-experimental@7988

@tanstack/solid-query

pnpm add https://pkg.pr.new/@tanstack/solid-query@7988

@tanstack/react-query-persist-client

pnpm add https://pkg.pr.new/@tanstack/react-query-persist-client@7988

@tanstack/solid-query-devtools

pnpm add https://pkg.pr.new/@tanstack/solid-query-devtools@7988

@tanstack/solid-query-persist-client

pnpm add https://pkg.pr.new/@tanstack/solid-query-persist-client@7988

@tanstack/svelte-query

pnpm add https://pkg.pr.new/@tanstack/svelte-query@7988

@tanstack/svelte-query-devtools

pnpm add https://pkg.pr.new/@tanstack/svelte-query-devtools@7988

@tanstack/svelte-query-persist-client

pnpm add https://pkg.pr.new/@tanstack/svelte-query-persist-client@7988

@tanstack/vue-query

pnpm add https://pkg.pr.new/@tanstack/vue-query@7988

@tanstack/vue-query-devtools

pnpm add https://pkg.pr.new/@tanstack/vue-query-devtools@7988

commit: cb0dfb4

Comment thread packages/query-core/src/queryObserver.ts Outdated
@KATT

This comment was marked as outdated.

@KATT
KATT force-pushed the discussions-7980-promises branch from ec583d5 to 8cbd6a0 Compare September 1, 2024 19:32
@KATT

This comment was marked as outdated.

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Sep 27, 2024
@KATT

KATT commented Sep 27, 2024

Copy link
Copy Markdown
Contributor Author

I added some docs

Comment thread docs/reference/QueryClient.md Outdated
Comment thread docs/framework/react/reference/queryOptions.md Outdated

@TkDodo TkDodo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ephem are you good with shipping this?

@TkDodo

TkDodo commented Oct 1, 2024

Copy link
Copy Markdown
Collaborator

since the whole feature is experimental (you need to opt into experimental_prefetchInRender for it to work), we can ship it and iterate later 🎉

@TkDodo
TkDodo merged commit 18953be into TanStack:main Oct 1, 2024
zemnmez-renovate-bot added a commit to zemn-me/monorepo that referenced this pull request Oct 1, 2024
##### [`v5.59.0](https://github.com/TanStack/query/releases/tag/v5.59.0)

Version 5.59.0 - 10/1/24, 3:45 PM

#### Changes

##### Feat

-   add support for `React.use()` ([#7988](TanStack/query#7988)) ([`18953be`](TanStack/query@18953be)) by [@KATT](https://github.com/KATT)

##### Docs

-   react-query: Fix broken route on eslint-plugin-query.md ([#8113](TanStack/query#8113)) ([`55a6155`](TanStack/query@55a6155)) by Gaurav Kumar
-   react-query: fix a typo in guides/ssr.md ([#8086](TanStack/query#8086)) ([`9227fd3`](TanStack/query@9227fd3)) by Morteza
-   angular-query: add rxjs example ([#8108](TanStack/query#8108)) ([`68ca717`](TanStack/query@68ca717)) by Arnoud

##### Other

-   ([`c12587a`](TanStack/query@c12587a)) by [@laurentlahmy](https://github.com/laurentlahmy)

#### Packages

-   [@tanstack/query-core](https://github.com/tanstack/query-core)[@5](https://github.com/5).59.0
-   [@tanstack/react-query](https://github.com/tanstack/react-query)[@5](https://github.com/5).59.0
-   [@tanstack/solid-query](https://github.com/tanstack/solid-query)[@5](https://github.com/5).59.0
-   [@tanstack/query-broadcast-client-experimental](https://github.com/tanstack/query-broadcast-client-experimental)[@5](https://github.com/5).59.0
-   [@tanstack/query-persist-client-core](https://github.com/tanstack/query-persist-client-core)[@5](https://github.com/5).59.0
-   [@tanstack/query-sync-storage-persister](https://github.com/tanstack/query-sync-storage-persister)[@5](https://github.com/5).59.0
-   [@tanstack/react-query-devtools](https://github.com/tanstack/react-query-devtools)[@5](https://github.com/5).59.0
-   [@tanstack/react-query-persist-client](https://github.com/tanstack/react-query-persist-client)[@5](https://github.com/5).59.0
-   [@tanstack/react-query-next-experimental](https://github.com/tanstack/react-query-next-experimental)[@5](https://github.com/5).59.0
-   [@tanstack/solid-query-devtools](https://github.com/tanstack/solid-query-devtools)[@5](https://github.com/5).59.0
-   [@tanstack/solid-query-persist-client](https://github.com/tanstack/solid-query-persist-client)[@5](https://github.com/5).59.0
-   [@tanstack/svelte-query](https://github.com/tanstack/svelte-query)[@5](https://github.com/5).59.0
-   [@tanstack/svelte-query-devtools](https://github.com/tanstack/svelte-query-devtools)[@5](https://github.com/5).59.0
-   [@tanstack/svelte-query-persist-client](https://github.com/tanstack/svelte-query-persist-client)[@5](https://github.com/5).59.0
-   [@tanstack/vue-query](https://github.com/tanstack/vue-query)[@5](https://github.com/5).59.0
-   [@tanstack/vue-query-devtools](https://github.com/tanstack/vue-query-devtools)[@5](https://github.com/5).59.0
-   [@tanstack/angular-query-experimental](https://github.com/tanstack/angular-query-experimental)[@5](https://github.com/5).59.0
-   [@tanstack/query-async-storage-persister](https://github.com/tanstack/query-async-storage-persister)[@5](https://github.com/5).59.0
-   [@tanstack/angular-query-devtools-experimental](https://github.com/tanstack/angular-query-devtools-experimental)[@5](https://github.com/5).59.0
zemnmez-renovate-bot added a commit to zemn-me/monorepo that referenced this pull request Oct 1, 2024
##### [`v5.59.0](https://github.com/TanStack/query/releases/tag/v5.59.0)

Version 5.59.0 - 10/1/24, 3:45 PM

#### Changes

##### Feat

-   add support for `React.use()` ([#7988](TanStack/query#7988)) ([`18953be`](TanStack/query@18953be)) by [@KATT](https://github.com/KATT)

##### Docs

-   react-query: Fix broken route on eslint-plugin-query.md ([#8113](TanStack/query#8113)) ([`55a6155`](TanStack/query@55a6155)) by Gaurav Kumar
-   react-query: fix a typo in guides/ssr.md ([#8086](TanStack/query#8086)) ([`9227fd3`](TanStack/query@9227fd3)) by Morteza
-   angular-query: add rxjs example ([#8108](TanStack/query#8108)) ([`68ca717`](TanStack/query@68ca717)) by Arnoud

##### Other

-   ([`c12587a`](TanStack/query@c12587a)) by [@laurentlahmy](https://github.com/laurentlahmy)

#### Packages

-   [@tanstack/query-core](https://github.com/tanstack/query-core)[@5](https://github.com/5).59.0
-   [@tanstack/react-query](https://github.com/tanstack/react-query)[@5](https://github.com/5).59.0
-   [@tanstack/solid-query](https://github.com/tanstack/solid-query)[@5](https://github.com/5).59.0
-   [@tanstack/query-broadcast-client-experimental](https://github.com/tanstack/query-broadcast-client-experimental)[@5](https://github.com/5).59.0
-   [@tanstack/query-persist-client-core](https://github.com/tanstack/query-persist-client-core)[@5](https://github.com/5).59.0
-   [@tanstack/query-sync-storage-persister](https://github.com/tanstack/query-sync-storage-persister)[@5](https://github.com/5).59.0
-   [@tanstack/react-query-devtools](https://github.com/tanstack/react-query-devtools)[@5](https://github.com/5).59.0
-   [@tanstack/react-query-persist-client](https://github.com/tanstack/react-query-persist-client)[@5](https://github.com/5).59.0
-   [@tanstack/react-query-next-experimental](https://github.com/tanstack/react-query-next-experimental)[@5](https://github.com/5).59.0
-   [@tanstack/solid-query-devtools](https://github.com/tanstack/solid-query-devtools)[@5](https://github.com/5).59.0
-   [@tanstack/solid-query-persist-client](https://github.com/tanstack/solid-query-persist-client)[@5](https://github.com/5).59.0
-   [@tanstack/svelte-query](https://github.com/tanstack/svelte-query)[@5](https://github.com/5).59.0
-   [@tanstack/svelte-query-devtools](https://github.com/tanstack/svelte-query-devtools)[@5](https://github.com/5).59.0
-   [@tanstack/svelte-query-persist-client](https://github.com/tanstack/svelte-query-persist-client)[@5](https://github.com/5).59.0
-   [@tanstack/vue-query](https://github.com/tanstack/vue-query)[@5](https://github.com/5).59.0
-   [@tanstack/vue-query-devtools](https://github.com/tanstack/vue-query-devtools)[@5](https://github.com/5).59.0
-   [@tanstack/angular-query-experimental](https://github.com/tanstack/angular-query-experimental)[@5](https://github.com/5).59.0
-   [@tanstack/query-async-storage-persister](https://github.com/tanstack/query-async-storage-persister)[@5](https://github.com/5).59.0
-   [@tanstack/angular-query-devtools-experimental](https://github.com/tanstack/angular-query-devtools-experimental)[@5](https://github.com/5).59.0
github-merge-queue Bot pushed a commit to zemn-me/monorepo that referenced this pull request Oct 1, 2024
##### [`v5.59.0](https://github.com/TanStack/query/releases/tag/v5.59.0)

Version 5.59.0 - 10/1/24, 3:45 PM

#### Changes

##### Feat

-   add support for `React.use()` ([#7988](TanStack/query#7988)) ([`18953be`](TanStack/query@18953be)) by [@KATT](https://github.com/KATT)

##### Docs

-   react-query: Fix broken route on eslint-plugin-query.md ([#8113](TanStack/query#8113)) ([`55a6155`](TanStack/query@55a6155)) by Gaurav Kumar
-   react-query: fix a typo in guides/ssr.md ([#8086](TanStack/query#8086)) ([`9227fd3`](TanStack/query@9227fd3)) by Morteza
-   angular-query: add rxjs example ([#8108](TanStack/query#8108)) ([`68ca717`](TanStack/query@68ca717)) by Arnoud

##### Other

-   ([`c12587a`](TanStack/query@c12587a)) by [@laurentlahmy](https://github.com/laurentlahmy)

#### Packages

-   [@tanstack/query-core](https://github.com/tanstack/query-core)[@5](https://github.com/5).59.0
-   [@tanstack/react-query](https://github.com/tanstack/react-query)[@5](https://github.com/5).59.0
-   [@tanstack/solid-query](https://github.com/tanstack/solid-query)[@5](https://github.com/5).59.0
-   [@tanstack/query-broadcast-client-experimental](https://github.com/tanstack/query-broadcast-client-experimental)[@5](https://github.com/5).59.0
-   [@tanstack/query-persist-client-core](https://github.com/tanstack/query-persist-client-core)[@5](https://github.com/5).59.0
-   [@tanstack/query-sync-storage-persister](https://github.com/tanstack/query-sync-storage-persister)[@5](https://github.com/5).59.0
-   [@tanstack/react-query-devtools](https://github.com/tanstack/react-query-devtools)[@5](https://github.com/5).59.0
-   [@tanstack/react-query-persist-client](https://github.com/tanstack/react-query-persist-client)[@5](https://github.com/5).59.0
-   [@tanstack/react-query-next-experimental](https://github.com/tanstack/react-query-next-experimental)[@5](https://github.com/5).59.0
-   [@tanstack/solid-query-devtools](https://github.com/tanstack/solid-query-devtools)[@5](https://github.com/5).59.0
-   [@tanstack/solid-query-persist-client](https://github.com/tanstack/solid-query-persist-client)[@5](https://github.com/5).59.0
-   [@tanstack/svelte-query](https://github.com/tanstack/svelte-query)[@5](https://github.com/5).59.0
-   [@tanstack/svelte-query-devtools](https://github.com/tanstack/svelte-query-devtools)[@5](https://github.com/5).59.0
-   [@tanstack/svelte-query-persist-client](https://github.com/tanstack/svelte-query-persist-client)[@5](https://github.com/5).59.0
-   [@tanstack/vue-query](https://github.com/tanstack/vue-query)[@5](https://github.com/5).59.0
-   [@tanstack/vue-query-devtools](https://github.com/tanstack/vue-query-devtools)[@5](https://github.com/5).59.0
-   [@tanstack/angular-query-experimental](https://github.com/tanstack/angular-query-experimental)[@5](https://github.com/5).59.0
-   [@tanstack/query-async-storage-persister](https://github.com/tanstack/query-async-storage-persister)[@5](https://github.com/5).59.0
-   [@tanstack/angular-query-devtools-experimental](https://github.com/tanstack/angular-query-devtools-experimental)[@5](https://github.com/5).59.0
@KATT
KATT deleted the discussions-7980-promises branch October 1, 2024 18:51
@jxom jxom mentioned this pull request Oct 8, 2024
@timvandam

Copy link
Copy Markdown

Hi @KATT, I came across the experimental_prefetchInRender property and think it would be a nice addition to allow prefetching during server-side rendering. Currently the prefetch branch is guarded with !isServer:

if (
defaultedOptions.experimental_prefetchInRender &&
!isServer &&
willFetch(result, isRestoring)
) {
const promise = isNewCacheEntry
? // Fetch immediately on render in order to ensure `.promise` is resolved even if the component is unmounted
fetchOptimistic(defaultedOptions, observer, errorResetBoundary)
: // subscribe to the "cache promise" so that we can finalize the currentThenable once data comes in
client.getQueryCache().get(defaultedOptions.queryHash)?.promise
promise?.catch(noop).finally(() => {
// `.updateResult()` will trigger `.#currentThenable` to finalize
observer.updateResult()
})
}

Changing the type from boolean to e.g. boolean | 'server' | 'client' | 'all' would make it very easy to set up server-side rendering in Vite based setups that don't use suspense by simply waiting for fetches to resolve (eg like this https://github.com/timvandam/react-vite-trpc-ssr/blob/main/src/entry.server.tsx#L50-L68). What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants