Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

with-apollo-app rendering twice #5050

Closed
Enalmada opened this issue Aug 28, 2018 · 3 comments
Closed

with-apollo-app rendering twice #5050

Enalmada opened this issue Aug 28, 2018 · 3 comments

Comments

@Enalmada
Copy link
Contributor

Examples bug report

Example name

with-apollo-app

Describe the bug

PostList is rendering twice

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Edit components/PostList.js and add console.log at the top of the render function
  2. Refresh screen
  3. Note that console output prints twice

Expected behavior

Console log output only shows once.

System information

  • OS: Windows 10
  • Browser: Chrome
  • Version of Next.js: 6.1.1

Additional context

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.

@timneutkens
Copy link
Member

timneutkens commented Aug 28, 2018

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

@Enalmada
Copy link
Contributor Author

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!

@timneutkens
Copy link
Member

🙏

timneutkens pushed a commit that referenced this issue Sep 23, 2018
Noting per #5050 for new users of Apollo that they should not be concerned about multiple renders.
@lock lock bot locked as resolved and limited conversation to collaborators Aug 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants