Repository navigation
Conversation
β¦th fromHandle Co-authored-by: alexander <[email protected]>
Co-authored-by: alexander <[email protected]>
Co-authored-by: alexander <[email protected]>
β¦table_ Co-authored-by: alexander <[email protected]>
β¦es; fix ts-expect-error placement Co-authored-by: alexander <[email protected]>
β¦mes as deprecated aliases Co-authored-by: alexander <[email protected]>
β¦nite handle verbs Co-authored-by: alexander <[email protected]>
β¦ct-query/handles entrypoint The handle proxy only starts queries: prefetch, ensure and fetch (plus their Infinite forms), without the unstable_ prefix. ensure and fetch return the handle with the data they waited for. Reading stays on the options proxy with unstable_fromHandle. Co-authored-by: alexander <[email protected]>
β¦k-start-sse-chat Co-authored-by: alexander <[email protected]>
Co-authored-by: alexander <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
4 Skipped Deployments
|
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
@trpc/client
@trpc/next
@trpc/openapi
@trpc/react-query
@trpc/server
@trpc/tanstack-react-query
@trpc/upgrade
commit: |
Co-authored-by: alexander <[email protected]>
Co-authored-by: alexander <[email protected]>
Co-authored-by: alexander <[email protected]>
Co-authored-by: alexander <[email protected]>
β¦quest waterfalls Co-authored-by: alexander <[email protected]>
Contributor
|
This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you. |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An alternative to #7759. It builds on #7759's commits: this compare view shows only what differs. Merge one or the other, not both.
Why
$helpers (unstable_$prefetch,unstable_$ensure,unstable_$fetch,unstable_$fromHandle)Β #7759, the verbs that start queries sit on the options proxy next toqueryOptions,queryKeyand the filters. Each verb needs its ownunstable_prefix, anduseTRPC()has them in its type but throws at runtime.trpc.post.byId.prefetch({ id }).prefetchdoesn't wait.ensurewaits for data.fetchwaits for fresh data.What
A new entrypoint,
@trpc/tanstack-react-query/handles, with a proxy that only starts queries:prefetch,ensureandfetch, plusprefetchInfinite,ensureInfiniteandfetchInfinitewhen the input has acursor. They map toprefetchQuery,ensureQueryData({ revalidateIfStale: true })andfetchQuery, and to the infinite versions of each.unstable_prefix. The prefix is on the way in:unstable_createTRPCHandleProxy,unstable_TRPCHandleProxyand the handle types.ensureandfetchresolve to the handle plusdata, so a loader can branch on the data and a server component can render it. feat(tanstack-react-query): query handles with$helpers (unstable_$prefetch,unstable_$ensure,unstable_$fetch,unstable_$fromHandle)Β #7759 left data off handles. The cost is thatdatais serialized with the handle wherever you pass it, and with a transformer inserializeDatait crosses a second time.input, typed from the procedure, so a component that gets a handle doesn't also need its input as a prop. Infinite handles leave outcursoranddirection, matching the query key; the starting cursor stays ininitialCursor. The input is already in the query key, so it now crosses twice; inputs are usually small.unstable_useWaterfall(useTRPC().x, input), from the same entrypoint, is the explicit escape hatch for a query whose input is only known at render time. It starts the query during render and returns a handle, so the reader is the same as for a loader's handle. The name marks every waterfall in a codebase. Query procedures only; the docs import itas useWaterfallfor the rules-of-hooks lint rule.await trpc.x.ensure()thenprefetchfrom itsdata, orunstable_useWaterfall) only when you can't.unstable_fromHandlefor reading, souseTRPC()no longer has verbs that throw, anddisableHandleVerbsis gone.@trpc/tanstack-react-query/handles:unstable_createTRPCHandleProxy,unstable_TRPCHandleProxy,unstable_useWaterfall,unstable_TRPCQueryHandle,unstable_TRPCInfiniteQueryHandle,unstable_TRPCQueryHandleWithData,unstable_TRPCInfiniteQueryHandleWithData,unstable_AnyTRPCHandle,unstable_TRPCPrefetchOptions,unstable_TRPCPrefetchInfiniteOptions,unstable_inferQueryHandle,unstable_inferInfiniteQueryHandle. The main entry keepsunstable_TRPCQueryHandle,unstable_TRPCInfiniteQueryHandleandunstable_AnyTRPCHandlefor readers.localLinkrename from feat(tanstack-react-query): query handles with$helpers (unstable_$prefetch,unstable_$ensure,unstable_$fetch,unstable_$fromHandle)Β #7759 is included unchanged.trpc.channel.list.prefetch()andtrpc.post.infinite.prefetchInfinite({ channelId }). Components still read withuseTRPC().unstable_fromHandle(...).ChatanduseLivePoststake only the posts handle and readchannelIdfromposts.input.Links
prefetch,ensureandfetch, withdataon waited-for handles.handle.input.TRPCHandlestype from the handle proxy.unstable_useWaterfall.trpc/server.tsxexports a handle proxy.createTRPCOptionsProxy.post.datain the loader./: the channel list is server-rendered from aprefetch()handle./channels/<id>: channels and posts come from handles, and "Load more" paginates the infinite handle.A different root proxy (not in this PR)
This PR adds a proxy that only starts queries, next to
createTRPCOptionsProxy. A bigger option is one root proxy that is the whole handle-first API. It's written down here in case we revisit it.What it would have:
trpc.post.byId.prefetch,ensureandfetch.useQuery(handle)returning[data, controls]for a handle fromensureorfetch, and[promise, controls]for one fromprefetch, instead ofuseSuspenseQuery(useTRPC().unstable_fromHandle(handle)).invalidate,setData,getData,resetandremove.await trpc.post.create.mutate(input), theninvalidate), withoutmutationOptions.What it would buy:
unstable_fromHandleplumbing in every component.unstable_useWaterfall, which keeps request waterfalls out of the default path.What it would cost:
createTRPCOptionsProxy, with its own docs, types, tests and migration guide.select,placeholderDataand the status flags).queryOptions, such asuseQueriesor third-party helpers, would still need the options proxy.When to revisit:
useTRPC().unstable_fromHandle(...)reads as boilerplate.This PR doesn't block that path. The handle proxy and its types are already apart from the options proxy, so a reader and cache verbs could join the
handlesentrypoint without changingcreateTRPCOptionsProxy.Testing
packages/tanstack-react-query/test/handles.test.tsx(26 tests): feat(tanstack-react-query): query handles with$helpers (unstable_$prefetch,unstable_$ensure,unstable_$fetch,unstable_$fromHandle)Β #7759's tests, moved to start handles on the handle proxy, plus:ensureandfetchreturndatawith the handle, typed from the procedure's output.input, withoutcursorfor infinite handles, and keep it through serialization.queryOptions, andprefetchInfiniteonly exists on procedures with acursorinput.unstable_useWaterfallstarts the query in render, returns a typed handle, doesn't refetch on re-render, and starts a new query when the input changes.useTRPC()has no verbs in its type.packages/tanstack-react-query/test/handles.ssr.test.tsx: server rendering from the dehydrated state with superjson andDatevalues, now starting on the handle proxy.pnpm buildregenerates the package'sexportsandturbo.jsonoutputs for./handles.typecheck,lintandlint-prunepass, andpnpm test -- --watch falsepasses (1390 tests).typecheck,lintand the productionbuildpass. I ran the build against a scratch local Postgres with one seeded channel./and/channels/<id>returned 200 and server-rendered the channel. The server logged no errors or handle warnings.Need help on this PR? Tag
@codesmith-botwith what you need.