question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

v12.1.5 regression with apollo client in SSR

See original GitHub issue

Verify canary release

  • I verified that the issue exists in Next.js canary release

Provide environment information

  Operating System:
      Platform: darwin
      Arch: x64
      Version: Darwin Kernel Version 21.4.0: Mon Feb 21 20:34:37 PST 2022; root:xnu-8020.101.4~2/RELEASE_X86_64
    Binaries:
      Node: 14.19.1
      npm: 6.14.16
      Yarn: 1.22.17
      pnpm: N/A
    Relevant packages:
      next: 12.1.5
      react: 17.0.2
      react-dom: 17.0.2

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

we use the classic approach of doing ssr with @apollo/client where it runs getDataFromTree on the server and hydrates the client in a getInitialProps function.

when I upgraded next from 12.1.4 to 12.1.5 this broke:

Error while running `getDataFromTree` Invariant Violation: Could not find "client" in the context or passed in as an option. Wrap the root component in an <ApolloProvider>, or pass an ApolloClient instance in via options.
    at new InvariantError (/path/project/node_modules/@apollo/client/node_modules/ts-invariant/lib/invariant.esm.js:12:28)
    at Object.invariant (/path/project/node_modules/@apollo/client/node_modules/ts-invariant/lib/invariant.esm.js:24:15)
    at useApolloClient (/path/project/node_modules/@apollo/client/react/hooks/useApolloClient.js:7:15)
    at useQuery (/path/project/node_modules/@apollo/client/react/hooks/useQuery.js:13:18)
    at useAssortment (webpack-internal:///./src/modules/categories/hooks/useAssortment.ts:31:97)
    at CategoryPage (webpack-internal:///./src/modules/categories/components/ShopRegularCategory.tsx:56:122)
    at processChild (/path/project/node_modules/react-dom/cjs/react-dom-server.node.development.js:3353:14)
    at resolve (/path/project/node_modules/react-dom/cjs/react-dom-server.node.development.js:3270:5)
    at ReactDOMServerRenderer.render (/path/project/node_modules/react-dom/cjs/react-dom-server.node.development.js:3753:22)
    at ReactDOMServerRenderer.read (/path/project/node_modules/react-dom/cjs/react-dom-server.node.development.js:3690:29) {
  framesToPop: 1
}

Expected Behavior

this kind of setup should not be affected by a patch-release

To Reproduce

will try to provide later, i still need to gather information and try to find out which actual change is the root cause o this bug.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:10
  • Comments:17 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
macrozonecommented, Apr 14, 2022

Thanks for the repro, but for completeness, @macrozone could you also add one for your case?

FWIW @KATT, I think react-query only recently started supporting React 18 in their v4 beta: https://github.com/tannerlinsley/react-query/releases/tag/v4.0.0-beta.1. Not sure yet if related, but I wanted to mention it.

Not sure if I can provide one in the next few hours or days. One important thing to know is, that its not about react 18. Its happening with react 17.

conceptually my case is very similar to the one @KATT provided with his TRPC example. There the App component in pages/_app is wrapped in a HOC withTRPC which provides the right context and collects data on SSR to hydrate the client cache. My guess is that there might be a problem how the App-component of _app is mounted

3reactions
KATTcommented, Apr 20, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Server-side rendering - Apollo GraphQL Docs
Server-side rendering (SSR) is a performance optimization for modern web apps. It enables you to render your app's initial state to raw HTML...
Read more >
Getting Started With Apollo Client in Next.js
In this post, we'll briefly cover each way to fetch and render data with Next.js, along with the important considerations for each approach....
Read more >
Server-side rendering - Apollo GraphQL Docs
These functions take care of the job of fetching all queries that are required to rendering your component tree. Typically you would use...
Read more >
Building a Next.js App with Apollo Client & Slash GraphQL
initialState }); } // For SSG and SSR always create a new Apollo Client ... fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 ...
Read more >
SSR - Apollo GraphQL Docs
SSR. Apollo Client React server side rendering API. Installation. Apollo Client >= 3 includes React hooks functionality out of the box.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found