Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

conditional rsc or trpc client #32

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sachinraja
Copy link
Member

this makes it so you can call the server and client from the same object (rsc, for now).

@vercel
Copy link

vercel bot commented Nov 1, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
next-13 ❌ Failed (Inspect) Nov 1, 2022 at 1:44PM (UTC)

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();
Copy link
Member

Choose a reason for hiding this comment

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

Wat, this works?

Copy link
Member Author

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

Copy link
Member

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 🤔

Copy link
Member Author

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" })],
Copy link
Member

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?

Copy link
Member Author

@sachinraja sachinraja Nov 1, 2022

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

Copy link
Member

@KATT KATT left a 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?

@KATT
Copy link
Member

KATT commented Nov 1, 2022

Another thing to consider is #4, we might not want to do this altogether....

@sachinraja
Copy link
Member Author

sachinraja commented Nov 1, 2022

Will we be able to do this as a proper package so the user won't have to setup a monorepo themselves?

The user has to implement the separate client and server code because they have to pass server-specific things like appRouter to createTRPCLayout.

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";
Copy link
Member

Choose a reason for hiding this comment

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

hmmm

Suggested change
import { rsc } from "~/server-rsc/trpc/client";
import { rsc } from "~/server-rsc/trpc";

does this still work?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants