You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
As you might all know that there is a package called "server-only", and when you use that package as "import 'server-only" in a file, it makes that file a server module, and if you try to import it in a client component, the development server will stop and will warn you about it, as expected. This is used for security purposes. BUT types should be allowed to be imported in client component, as TypeScript types are erased during compilation, so they don't affect the runtime behavior.
This issues makes tRPC impractical to use, as client tRPC instance should have the type of the routers (routers are collection of Procedures, the P in tRPC). Below is my code sample:
import { createTRPCClient, httpBatchLink } from '@trpc/client';
import type { APP_ROUTER_TYPE } from './routers';
export const TRPC_CLIENT = createTRPCClient<APP_ROUTER_TYPE>({
links: [
httpBatchLink({
url: 'http://localhost:8081/rpc',
}),
],
});
And that TRPC_CLIENT instance is supposed to be used in client components, but I can't as One warns me that server-only modules cannot be used in client components.
Please make One to behave according to the expected behavior of server-only, which is allowing types to be imported to client components from server-only modules, and disallowing the rest (i.e. values, functions, etc).
Please note that I tested these in Next.js to see if it also has same issue, but it successfully allowed importing the types to client components.
The text was updated successfully, but these errors were encountered:
Hello,
As you might all know that there is a package called "server-only", and when you use that package as "import 'server-only" in a file, it makes that file a server module, and if you try to import it in a client component, the development server will stop and will warn you about it, as expected. This is used for security purposes. BUT types should be allowed to be imported in client component, as TypeScript types are erased during compilation, so they don't affect the runtime behavior.
This issues makes tRPC impractical to use, as client tRPC instance should have the type of the routers (routers are collection of Procedures, the P in tRPC). Below is my code sample:
And that TRPC_CLIENT instance is supposed to be used in client components, but I can't as One warns me that server-only modules cannot be used in client components.
Please make One to behave according to the expected behavior of server-only, which is allowing types to be imported to client components from server-only modules, and disallowing the rest (i.e. values, functions, etc).
Please note that I tested these in Next.js to see if it also has same issue, but it successfully allowed importing the types to client components.
The text was updated successfully, but these errors were encountered: