apollographql / apollo-client-nextjs

Apollo Client support for the Next.js App Router
https://www.npmjs.com/package/@apollo/experimental-nextjs-app-support
MIT License
436 stars 32 forks source link

useSuspenseQuery - bug or expected? Queries waterfalling in React 18 #327

Closed tombryden closed 2 months ago

tombryden commented 2 months ago

Hi,

In Next.js, I am seeing that if I navigate directly to a page with 2x components that fetch data in one Suspense boundary, suspense works as I expect (in React 18) - the queries run in parallel via SSR streaming.

      <Suspense fallback={<div>Loading...</div>}>
        <FetchSomeData />
        <FetchMoreData />
      </Suspense>

However, the same code will waterfall if not using Next.js SSR streaming (e.g. having a toggle to render the suspense boundary, or navigating to a page via a <Link />)

I could be wrong but I thought Suspense was supposed to run in parallel, hence the uproar regarding React 19 potentially changing this?

For more info, TkDodo's blog post on React 19 and Suspense - https://tkdodo.eu/blog/react-19-and-suspense-a-drama-in-3-acts

phryneas commented 2 months ago

React 19 potentially changing this?

There's nothing potential about it - that change shipped months ago into frameworks consuming experimental or canary builds of React like Next.js 😅

It will be rolled back for React 19, but right now this is the behaviour of React in Next.js (they are not really using React 18)

tombryden commented 2 months ago

Oh wow, I'm behind the times - didn't realise Next.js had already shipped this. Cheers

github-actions[bot] commented 2 months ago

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.