Apollo-client: Sharing patch we use to fix stale cache/query bugs

Created on 11 Feb 2020  路  1Comment  路  Source: apollographql/apollo-client

Intended outcome:

I believe this is related to:

3633, #5781, #5790

https://github.com/apollographql/react-apollo/issues/3774
https://github.com/apollographql/react-apollo/issues/3361

Actual outcome:

This is the patch-package we're using at Cypress to fix this:

diff --git a/node_modules/@apollo/client/apollo-client.cjs.js b/node_modules/@apollo/client/apollo-client.cjs.js
index 91ed213..8426975 100644
--- a/node_modules/@apollo/client/apollo-client.cjs.js
+++ b/node_modules/@apollo/client/apollo-client.cjs.js
@@ -931,6 +931,8 @@ var ObservableQuery = (function (_super) {
                     else {
                         iterateObserversSafely(_this.observers, 'next', result);
                     }
+                } else {
+                    iterateObserversSafely(_this.observers, 'next', result);
                 }
             },
             error: onError,
diff --git a/node_modules/@apollo/client/core/ObservableQuery.js b/node_modules/@apollo/client/core/ObservableQuery.js
index fe1b844..4898eab 100644
--- a/node_modules/@apollo/client/core/ObservableQuery.js
+++ b/node_modules/@apollo/client/core/ObservableQuery.js
@@ -333,6 +333,8 @@ var ObservableQuery = (function (_super) {
                     else {
                         iterateObserversSafely(_this.observers, 'next', result);
                     }
+                } else {
+                    iterateObserversSafely(_this.observers, 'next', result);
                 }
             },
             error: onError,

I don't know if this is necessarily the "correct" place to fix the issue, because it ends up triggering the observable more often than you'd normally want. But it does the trick and fixes this stale data for us, which IIRC was due to a super hard to track down and reproduce non-deterministic race-condition around deep equality in the in-memory store - we only were able to eventually reproduce and fix because of how fast the test suite runs.

Mostly just sharing to see if others can try it out and see if it helps with their issues, which might in-turn help the Apollo devs narrow down and fix the source of the underlying issue.

How to reproduce the issue:

See other issues.

Versions

3.0

Most helpful comment

Thanks @tgriesser! I remember you mentioning something about this at Summit. We will make sure to address this issue the right way (whatever that turns out to be) before the AC3 release.

>All comments

Thanks @tgriesser! I remember you mentioning something about this at Summit. We will make sure to address this issue the right way (whatever that turns out to be) before the AC3 release.

Was this page helpful?
0 / 5 - 0 ratings