with-apollo-app
PostList is rendering twice
Steps to reproduce the behavior, please provide code snippets or a repository:
Console log output only shows once.
I am completely new to react/next/apollo and trying to learn how to do things right from the wonderful examples. If you could please take a moment to fix the example so that it only renders once, that would make new users much more comfortable knowing they are following the right pattern. Thank you very much for your help.
If you could please take a moment to fix the example so that it only renders once, that would make new users much more comfortable knowing they are following the right pattern.
There's nothing to fix here, it's the way Apollo works:
https://www.apollographql.com/docs/react/features/server-side-rendering.html#getDataFromTree
Apollo recursively traverses the React render tree looking for Apollo query components. When it has done that, it fetches all these queries and then passes the result to a cache. This cache is then used to render the data on the server side (another React render). This is the reason you're seeing 2 renders being executed.
Thanks for taking the time to try and improve the example for everyone though 馃檹馃檶 Feel free to send a pull request with this additional context to the example readme
Thank you so much for taking the time to confirm that. When I know next/apollo better I am sure I will do a facepalm for asking that. Your confirmation of that really helps me feel more comfortable getting started now with next!
:pray:
Most helpful comment
There's nothing to fix here, it's the way Apollo works:
https://www.apollographql.com/docs/react/features/server-side-rendering.html#getDataFromTree
Apollo recursively traverses the React render tree looking for Apollo query components. When it has done that, it fetches all these queries and then passes the result to a cache. This cache is then used to render the data on the server side (another React render). This is the reason you're seeing 2
renders being executed.Thanks for taking the time to try and improve the example for everyone though 馃檹馃檶 Feel free to send a pull request with this additional context to the example readme