-
Notifications
You must be signed in to change notification settings - Fork 25
conditional rsc or trpc client #32
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
import { Inputs } from "~/shared/utils"; | ||
|
||
export function CreatePostForm() { | ||
const addPost = trpc.post.add.useMutation(); | ||
// const a = rsc.health.healthz.use(); | ||
|
||
const data = rsc.health.healthz.use(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wat, this works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, see my other comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhhhhh, I missed that this was imported from the /client
....
I think this isn't great as you'll have to keep track of which one you're using 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was a mistake (auto import). server-rsc/trpc
should work too.
TRouter extends AnyRouter | ||
>(): Promise<DecoratedProcedureRecord<TRouter["_def"]["record"]>> { | ||
const client = createTRPCClient({ | ||
links: [httpBatchLink({ url: "/api/trpc" })], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the server I think we'd need some sort of server-link?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wouldn't run on the server. @trpc/next-layout/server.ts
is the one that runs on server components. The server-rsc
directory has a package.json
with the react-server
condition to switch between server and client automatically
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohhhh this is cool.
Will we be able to do this as a proper package so the user won't have to setup a monorepo themselves?
Another thing to consider is #4, we might not want to do this altogether.... |
The user has to implement the separate client and server code because they have to pass server-specific things like Either way seems like this isn't a good idea. It would also force everyone to use Suspense because we'd have to ensure the data is actually there when they're using it (like RSC). |
@@ -2,10 +2,15 @@ | |||
|
|||
import { useRouter } from "next/navigation"; | |||
import { trpc } from "~/client/trpcClient"; | |||
import { rsc } from "~/server-rsc/trpc/client"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm
import { rsc } from "~/server-rsc/trpc/client"; | |
import { rsc } from "~/server-rsc/trpc"; |
does this still work?
this makes it so you can call the server and client from the same object (
rsc
, for now).