urql-graphql / urql

The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
https://urql.dev/goto/docs
MIT License
8.57k stars 444 forks source link

createContext only works in Client Components error with latest NextJS #3359

Closed khuong-tran closed 11 months ago

khuong-tran commented 11 months ago

Describe the bug

Hi, anyone encountered this bug with Server Component? I'm using next 13.4.19, all @urql/core and @urql/next version are latest image

Reproduction

Just copy the example

Urql version

"urql": "^4.0.5" "@urql/core": "^4.1.1" "@urql/next": "^1.0.0"

Validations

JoviDeCroock commented 11 months ago

I tried running the example and it ran just fine for me 😅 with the versions you are mentioning

khuong-tran commented 11 months ago

Nevermind, I just read the error log, the problem is in the generated file by graphql code gen, thank you for your quick response though, I'm closing this now. Have a great day!

geisterfurz007 commented 10 months ago

It does not for me unfortunately. Importing urql calls createContext as a side-effect but is needed to import the exchanges to create the client if I am not missing anything.

The most minimal thing I can put together to repro is this page.js:

import {createClient} from "@urql/next";

// Required so the import is not optimized away
console.log(createClient)

export default function Home() {
  return <div />
}

Versions are:

  "dependencies": {
    "@urql/next": "1.0.0",
    "next": "13.5.3",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "urql": "4.0.5"
  }
geisterfurz007 commented 10 months ago

I am down to work on a solution for this btw; I am just not sure if I am doing something wrong so if someone from the maintainer team could confirm my understanding of this issue, that would be awesome :) And if it turns out that importing anything from urql is indeed causing a side-effect breaking on RSCs, I would appreciate a nudge in the right direction for a solution; I am not super familiar with structuring of a library.

geisterfurz007 commented 10 months ago

@JoviDeCroock I don't mean to be super annoying but is there a chance you could double check if I am doing something utterly wrong here?

JoviDeCroock commented 10 months ago

You can import the exchanges from @urql/core

geisterfurz007 commented 10 months ago

Oof, that's embarassing... I completely missed that in the example, sorry! Through my mix of client and server use I thought it was a good idea to make a joined makeClient function and imported everything through @urql/next instead of core in there.

Thanks a bunch and sorry for bothering!