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

Query doesn't wait for Mutation to finish #81

Closed
garrett-thompson opened this issue May 18, 2018 · 6 comments
Closed

Query doesn't wait for Mutation to finish #81

garrett-thompson opened this issue May 18, 2018 · 6 comments
Labels
needs more info ✋ A question or report that needs more info to be addressable

Comments

@garrett-thompson
Copy link

garrett-thompson commented May 18, 2018

I have a component like so:

<Connect
  query={query(getItemsQuery)}
  mutation={{
    updateItem: mutation(updateItemMutation)
  }}
  children={({ data, updateItem }) => {
  ...

When I fire the updateItem mutation, the getItems query is immediately reran, giving me items back before the mutation finishes. This results in a weird ux where a user edits a field, hits "save" (updateItem), and the field flashes back to it's old value, then to the new value again.

Is the query supposed to fire again before the mutation completes?

@kitten
Copy link
Member

kitten commented May 19, 2018

Can you try whether this is still an issue with 0.3.0-next1 please? You can install it using the “next” tag.

@garrett-thompson
Copy link
Author

Yea, still doing it on 0.3.0-next1.

When I add if (data) console.log("test"); inside the render prop, then fire the mutation once (via onClick), I see this in the console:

screen shot 2018-05-19 at 2 25 27 pm

Seems a little excessive.

@kitten
Copy link
Member

kitten commented May 19, 2018

I think we'd need a reproduction on CodeSandbox to confirm this. There's only two calls to setState as a result of a mutation. Although afterwards a refetch on the query might cause two additional, but separate, rerenders of course.

There's also the case of calling query and mutation inline in your render method. This way you might accidentally trigger a refetch or an update (the latter in the best case scenario), so try to pull that out of your component, if possible, or into an instance variable and see if it improves the situation.

https://github.com/FormidableLabs/urql/blob/master/src/components/client.tsx#L57-L62

@kitten
Copy link
Member

kitten commented May 26, 2018

@mellogarrett any update? It'd be great if we could get a CodeSandbox running for this

@kitten kitten added the needs more info ✋ A question or report that needs more info to be addressable label May 26, 2018
@garrett-thompson
Copy link
Author

Hey @kitten I'm sorry, I ended up just using Axios to make graphql requests from componentDidMount rather than on every render via urql's render prop.

@kitten
Copy link
Member

kitten commented Jun 28, 2018

@mellogarrett Alright, since this is not reproducible right now and stale I'll close the issue. Sorry about that, let's see if someone else hits a similar case in the future

@kitten kitten closed this as completed Jun 28, 2018
kitten added a commit that referenced this issue Feb 5, 2020
* Add (non breaking) reproduction for #80

* Add missing clearOptimistic

* Ensure that pessimism is at 1.1.2

* Clean up new examples-1 test

* Upgrade to pessimism 1.1.3

* Remove obsolete snapshot
kitten pushed a commit that referenced this issue Feb 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info ✋ A question or report that needs more info to be addressable
Projects
None yet
Development

No branches or pull requests

2 participants