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

Optimistic response gets rolled back even if mutation errors are ignored in onError link #7815

Open
habovh opened this issue Mar 10, 2021 · 2 comments

Comments

@habovh
Copy link

habovh commented Mar 10, 2021

Intended outcome:
Optimistic response should not roll back in case of an error that is being ignored by the onError link.

Actual outcome:
Optimistic response gets rolled back even though the mutation errors are being ignored by onError link.

How to reproduce the issue:

  • Write a mutation that should trigger an error
  • Setup onError link to ignore errors from said mutation (e.g using operation.operationName to identify the mutation)
  • Call this mutation with an optimistic response
  • See that the optimistic response gets rolled back as soon as the server returned an error (e.g Internal Server Error)

Versions

  System:
    OS: macOS 11.2.3
  Binaries:
    Node: 14.3.0 - ~/.nvm/versions/node/v14.3.0/bin/node
    Yarn: 1.22.5 - /usr/local/bin/yarn
    npm: 6.14.5 - ~/.nvm/versions/node/v14.3.0/bin/npm
  Browsers:
    Chrome: 88.0.4324.192
    Firefox: 84.0.2
    Safari: 14.0.3
  npmPackages:
    @apollo/react-hoc: ^3.1.3 => 3.1.3 
    apollo-cache: ^1.3.2 => 1.3.2 
    apollo-cache-inmemory: ^1.6.3 => 1.6.3 
    apollo-client: ^2.6.4 => 2.6.4 
    apollo-client-preset: ^1.0.8 => 1.0.8 
    apollo-link: ^1.2.13 => 1.2.13 
    apollo-link-context: ^1.0.19 => 1.0.19 
    apollo-link-error: ^1.1.12 => 1.1.12 
    apollo-link-ws: ^1.0.19 => 1.0.19 
    apollo-utilities: ^1.3.2 => 1.3.2 
    react-apollo: ^3.1.3 => 3.1.3 
@benjamn
Copy link
Member

benjamn commented Mar 10, 2021

@habovh Although I know updating to Apollo Client 3 might not be an easy option, a lot has changed about the way optimistic mutation results work since AC2, so there's a good chance the ultimate answer to this issue is to upgrade to AC3.

Instead of migrating your whole app just to see if this problem goes away, do you think you could try reproducing the problem using this AC3 template? If it's not reproducible with AC3, that's good, and I hope that gives you another reason to upgrade. If the problem is still reproducible with AC3, that would also be great to know, so we can fix it properly.

@habovh
Copy link
Author

habovh commented Mar 11, 2021

Hi @benjamn, thanks for your feedback.

Indeed updating to AC3 seems like a good idea, we're currently holding it back for compatibility reasons with a third-party link provider, but will surely come to it at some point.

In the meantime, I've managed to reproduce the issue I'm encountering using the template you provided. You can find my clone here: habovh/react-apollo-error-template/tree/issue/7815.

Simply build the app and try to add a person. You'll see the person's name appearing directly in the list thanks to the optimistic response. But once the "actual server" responds —I've increased the fake server delay to 2000ms—, while you'll see no error on screen, the added name disappears, meaning the optimistic response got rolled back, despite the link explicitly removing any errors.

Hope this repro helps.

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