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

Make ApolloNextAppProvider usable out of the box #395

Closed
Sam-Kruglov opened this issue Nov 26, 2024 · 4 comments
Closed

Make ApolloNextAppProvider usable out of the box #395

Sam-Kruglov opened this issue Nov 26, 2024 · 4 comments

Comments

@Sam-Kruglov
Copy link

Sam-Kruglov commented Nov 26, 2024

I have to create a client component that forwards the children to it, I can't just use it directly. I think it should be usable in root layout as is without having to create an extra component

export default function RootLayout({
  children,
}: {
  children: React.ReactNode,
}) {
  return (
    <html lang="en">
      <body>
        <ApolloNextAppProvider makeClient={makeClient}>{children}</ApolloWrapper>
      </body>
    </html>
  );
}

This gives an error ⨯ Error: Unsupported Server Component type: undefined

@phryneas
Copy link
Member

phryneas commented Nov 27, 2024

We need you to create that additional file with "use client" on top so it is considered a client component by Next.js - you also could not pass makeClient over as a prop in a server component file, because the result of makeClient is non-serializable, and makeClient would be considered a server function reference that way.

These are not constraints that we are adding, but constraints added by React and your Framework - there's no way around that.

@Sam-Kruglov
Copy link
Author

Sam-Kruglov commented Nov 27, 2024

Why can’t this file be in the lib already? Just accept client prop and children, seems pretty simple to me.
Or maybe just mark ApolloNextAppProvider as use client

@phryneas
Copy link
Member

phryneas commented Nov 27, 2024

Because we cannot write makeClient for you (this is your configuration code), and it's impossible to pass makeClient from a server component into a client component.
This has to happen in your code base. Marking ApolloNextAppProvider as "use client" wouldn't change anything here.

Copy link
Contributor

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.

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

No branches or pull requests

2 participants