next.js: v12.1.5 regression with apollo client in SSR

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.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 10
  • Comments: 17 (8 by maintainers)

Most upvoted comments

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

My tests are now passing again as of next@12.1.6-canary.3! (https://github.com/vercel/next.js/pull/36206 & https://github.com/vercel/next.js/issues/36198)

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.

Official support, yes, but they have run their tests with react 18 for ages


I made a better repro (which is using react 17 as well).

I’ve invited you as a contributor, @balazsorban44, so if you wanna test a new canary or something, feel free to open a new PR that runs through the E2E test suite.

I wish I could provide an even better repro that didn’t have libraries, but I really don’t have time today.

thx guys, will check soon

It’s @macrozone’s issue, but I believe so yes