trpc
trpc copied to clipboard
Break out `withTRPC` from `createTRPCNext`?
Also, as you're pointing out, RSC will hopefully fix this for us. I don't want to put too much more effort into
withTRPCin it's current form as it will hopefully be deprecated pretty soon (that said, for v10, we should probably make sure we have an API design that makes it tree shakable when/if that happens 😅 )Originally posted by @KATT in https://github.com/trpc/trpc/issues/2625#issuecomment-1240397342
Maybe we should move the withTRPC to it's own import so it can be tree-shaken when/if RSC or the Next.js Layouts arrives so it can be tree-shaken as it will will likely have to be non-compatible to that API or make a bunch of stuff redundant.
Suggested change
Before
// _app.tsx
import { AppType } from 'next/dist/shared/lib/utils';
import { ReactElement, ReactNode } from 'react';
import { trpc } from '~/utils/trpc';
const MyApp: AppType = (({ Component, pageProps }) => {
return <Component {...pageProps} />;
})
export default trpc.withTRPC(MyApp);
After
Not thrilled about exactly this API-design, but gets the point across that
withTRPC()can be tree shaken, feel free to do other suggestions
// _app.tsx
import { AppType } from 'next/dist/shared/lib/utils';
import { trpc } from '~/utils/trpc';
import { createTRPCNextWithTRPC } from '@trpc/next';
const MyApp: AppType = (({ Component, pageProps }) => {
return <Component {...pageProps} />;
})
export default createWithTRPC(trpc)(MyApp);
We could also separate SSR and non-SSR to further minimize the bundle 🤷
Meh. Not prioritized right now.