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

Infinite initialization? (with Graphql-codegen and Next.js 13) #3408

Closed
3 tasks done
shkim opened this issue Oct 20, 2023 · 4 comments
Closed
3 tasks done

Infinite initialization? (with Graphql-codegen and Next.js 13) #3408

shkim opened this issue Oct 20, 2023 · 4 comments

Comments

@shkim
Copy link

shkim commented Oct 20, 2023

Describe the bug

When I use the Provider for urql client, it seems that it is infinitely called when any query is activated.

I prepared the reproducible example code: https://github.com/shkim/urql-next13-error
Remarkable files are:

src/app/GqlProvider.tsx
src/app/layout.tsx
src/app/query/page.tsx
src/graphql/index.ts
src/graphql/documents.tsx

src/graphql/generated.tsx file is generated with graphql-codegen
it can be regenerated by "graphql-codegen --config gql-config.yml"

Thank you.

Reproduction

https://github.com/shkim/urql-next13-error

Urql version

@urql/next 1.1.0 (latest at the moment)

Validations

  • I can confirm that this is a bug report, and not a feature request, RFC, question, or discussion, for which GitHub Discussions should be used
  • Read the docs.
  • Follow our Code of Conduct
@JoviDeCroock
Copy link
Collaborator

JoviDeCroock commented Oct 28, 2023

That's because this line should be importing from @urql/next.

Changing your codegen file to be the one underneath should fix the issue at hand.

schema: https://swapi-graphql.netlify.app/.netlify/functions/index
generates:
  ./src/graphql/generated.ts:
    documents: ./src/graphql/documents.graphql
    config:
      urqlImportFrom: "@urql/next"
    plugins:
      - typescript
      - typescript-operations
      - typescript-urql

The second issue here is that you are missing Suspense boundaries, so during SSR it throws and never keeps the GqlProvider alive meaning the state is constantly renewed so changing your layout to be the following should be the second fix.

import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";
import GqlProvider from "./GqlProvider";
import { Suspense } from "react";

const inter = Inter({ subsets: ["latin"] });

export const metadata: Metadata = {
  title: "Create Next App",
  description: "Generated by create next app",
};

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <body className={inter.className}>
        <GqlProvider>
          <Suspense>
          {children}
          </Suspense>
        </GqlProvider>
      </body>
    </html>
  );
}

@michaelzadra1
Copy link

I'm experiencing the same issue. I tried the above solution but it didn't resolve the problem.

Strangely enough, what resolves the infinite fetch problem for me is removing export const runtime = "edge"; from my Page components. There seems to be some issue with serving pages from edge fns w/ urql

@JoviDeCroock
Copy link
Collaborator

@michaelzadra1 That sounds like a different issue

@JoviDeCroock
Copy link
Collaborator

Going to close this issue out, feel free to create a new one for the edge issue! 🙌 will need an accompanying reproduction

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

3 participants