We should make official support for Next 13 app layouts & RSC.
Being able to transparently use tRPC identically in RSC-components and in "use client"
-components.
This is very open-ended and hard to answer without tonnes of exploration.
We've done some in https://github.com/trpc/next-13 and experiments of new Next.js adapters in https://github.com/trpc/examples-next-app-dir
Leverage "forked" versions of the tRPC client outlined by @sebmarkbage in this tweet.
.
βββ pages
βΒ Β βββ api
βΒ Β βββ [trpc].ts
βββ trpc
βββ index.ts # entrypoint for TS to be happy. Actually not used, `package.json` will magically route to `/entrypoints`
βββ package.json
βββ context.ts
βββ entrypoints
βΒ Β βββ client.ts # <-- this is what gets magically imported when importing `~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/trpc` on the client
βΒ Β βββ rsc.ts # <-- gets imported when importing `~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/trpc` in RSC
βββ routers
βββ _app.ts
βββ example.ts
With this structure we should be able to streamline the API to be exactly the same within RSC & in "use client"
components.
Again, it should not matter if the below is done within a RSC-component or in a "use client"
one.
import { use } from 'react';
import { trpc } from '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/trpc';
function MyComponent() {
const post = use(trpc.post.byId.query({ id: "1" }))
// [..]
}
createContext()
In the createContext
function we'll need to be able to distinguish what type of call it is.
Next 13 have some new magical headers()
and cookies
- we should probably call these or allow for a way of calling them within RSC.
function createContext(opts: CreateTRPCContextNextAppLayout /* maybe CreateTRPCContextNextAppLayoutEdgeApi too */ ) {
if (opts.type === "rsc") {
opts.headers
} else {
opts.req.headers
}
}
"use client"
that is fetched through SSR & when it's mounted on the client? React Query doesn't seem to support this yet (& I'm guessing it's because lack of support from React)ssrLink
to avoid calls over the network?From SyncLinear.com | T-74
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too