Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support for getLayout in generated _app.tsx #1363

Closed
AndKenneth opened this issue Apr 18, 2023 · 3 comments
Closed

feat: Support for getLayout in generated _app.tsx #1363

AndKenneth opened this issue Apr 18, 2023 · 3 comments
Labels
🌟 enhancement New feature or request

Comments

@AndKenneth
Copy link

AndKenneth commented Apr 18, 2023

Is your feature request related to a problem? Please describe.

Hi Yall. I've been trying to implement layouts on my T3 app and I've run into some issues integrating it with the way next recommends in their documentation.

https://nextjs.org/docs/basic-features/layouts

I've tried integrating this with my app, and while I can get it working in isolation, the particularities of the custom types involved gets very complex very quickly, and generally falls apart when I try and reintegrate trpc and nextauth as set up in ct3a.

Overall this is a fairly painful and frustrating experience for less experienced typescript developers that requires understanding what the types are doing here to solve.

Describe the solution you'd like to see

I'd propose that the generated _app.tsx file in ct3a supports exported pages including a getLayout function, and wraps the component in the layout per the Next.JS docs.

Describe alternate solutions

We could wait for app router to be fully supported which has a much more powerful and sane layout system. Julius recommended this approach in another issue.

I would argue that if someone who knows what they're doing could take a look at this, it could be a quick job, and would save newer developers a lot of pain. Maybe someone knows better than me that app router is coming soon so it's not worth it, but the linked issue is more than 6 months ago and I see a few recent bumps asking for a solution.

@AndKenneth AndKenneth added the 🌟 enhancement New feature or request label Apr 18, 2023
@Rykuno
Copy link

Rykuno commented May 4, 2023

type NextPageWithLayout = NextPage & {
  getLayout?: (page: React.ReactElement) => React.ReactNode;
};

type AppPropsWithLayout = AppType & {
  Component: NextPageWithLayout;
  pageProps: { session: Session | null };
};

const MyApp = ({
  Component,
  pageProps: { session, ...pageProps }
}: AppPropsWithLayout) => {
  const getLayout = Component.getLayout ?? (page => page);

....

@juliusmarminge
Copy link
Member

Rykuno's code looks about right. We have this in some of tRPC's examples but I don't think we're really using them post-setup 😓

@juliusmarminge
Copy link
Member

Closing this as we're getting closer to the app dir option and I don't think we want to make this change for pages

@juliusmarminge juliusmarminge closed this as not planned Won't fix, can't repro, duplicate, stale Jun 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌟 enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants