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

useQuery onCompleted is called with old data when query makes use of @export directive #10452

Open
mogzol opened this issue Jan 18, 2023 · 0 comments

Comments

@mogzol
Copy link

mogzol commented Jan 18, 2023

Issue Description

If a query is ever re-fetched (i.e. from a variable change), and the query makes use of the @export directive, then the onCompleted callback will incorrectly be called twice. First with the previous query result, and then with the new query result. Note that this only happens when the query is re-run. The very first time the query runs, onCompleted is only called once (as expected).

Link to Reproduction

https://codesandbox.io/s/apollo-oncompleted-issue-q5e9ss?file=/src/App.jsx

Reproduction Steps

  1. View the linked codesandbox reproduction
  2. Observe that initially upon loading, onCompleted is called once with the data for id: 1. This is correct so far.
  3. Click the "Update Data" button to change id to 2
  4. Observe that onCompleted is called two additional times. First with the old data for id: 1, and then again with the new data for id: 2.

Also note that does not happen if there is no @export directive in the query. In that case, changing id only results in one additional onCompleted call, the one with the new data.

@mogzol mogzol changed the title useQuery onCompleted is called with old data when query changes while using @export directive useQuery onCompleted is called with old data when query makes use of @export directive Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants