trpc icon indicating copy to clipboard operation
trpc copied to clipboard

Break out `withTRPC` from `createTRPCNext`?

Open KATT opened this issue 3 years ago • 1 comments

Also, as you're pointing out, RSC will hopefully fix this for us. I don't want to put too much more effort into withTRPC in 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);

KATT avatar Sep 08 '22 09:09 KATT

We could also separate SSR and non-SSR to further minimize the bundle 🤷

KATT avatar Sep 08 '22 10:09 KATT

Meh. Not prioritized right now.

KATT avatar Oct 20 '22 18:10 KATT