Open spetroll opened 1 year ago
Hey @spetroll 👋
I understand this is is not optimal and agree getDataFromTree
should try to be a bit more optimized. The good news is that we are focused on improvements to the SSR story with Apollo with React 18's renderToPipeableStream
. Take a look at the RFC for more details.
Unfortunately I can't guarantee we will spend much time with getDataFromTree
since we will likely encourage users to migrate to the React 18 capabilities, which provide much more robust behavior and UX.
Hopefully this provides you a bit of insight!
We are using
getDataFromTree
in our Next.js application to collect all data required before rendering a page on the server. As we know,getDataFromTree
runs multiple times when having nested queries to resolve all queries in theAppTree
. I hoped to reduce the number of rerenders by prefetching the queries. While the queries cache is primed with all required data, it still has to render the wholeAppTree
multiple times instead of once. It appears as ifgetDataFromTree
can't make use of the cached queries.Intended outcome:
getDataFromTree
should not ignore cached queries and render only once when all data is available.Actual outcome:
The cached queries are ignored and nested
useQuery
causes the wholeAppTree
to be rendered multiple times withgetDataFromTree
. (6 in my example)How to reproduce the issue:
I reproduced this issue in this codesandbox: https://codesandbox.io/p/sandbox/laughing-pasteur-q84rpu
Versions
System: OS: Linux 5.15 Debian GNU/Linux 11 (bullseye) 11 (bullseye) Binaries: Node: 16.17.0 - /usr/local/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 8.15.0 - /usr/local/bin/npm npmPackages: @apollo/client: 3.7.1 => 3.7.1