Skip to content

Commit

Permalink
Check structural equality in QueryInfo#setDiff.
Browse files Browse the repository at this point in the history
Should help with #6888.
  • Loading branch information
benjamn committed Aug 24, 2020
1 parent d470c96 commit 6c4280e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
12 changes: 2 additions & 10 deletions src/__tests__/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3028,11 +3028,9 @@ describe('@connection', () => {
client.cache.evict({ fieldName: "a" });
await wait();

// The results are structurally the same, but the result objects have
// been recomputed for queries that involved the ROOT_QUERY.a field.
expect(checkLastResult(aResults, a456)).not.toBe(a456);
expect(checkLastResult(aResults, a456)).toBe(a456);
expect(checkLastResult(bResults, bOyez)).toBe(bOyez);
expect(checkLastResult(abResults, a456bOyez)).not.toBe(a456bOyez);
expect(checkLastResult(abResults, a456bOyez)).toBe(a456bOyez);

const cQuery = gql`{ c }`;
// Passing cache-only as the fetchPolicy allows the { c: "see" }
Expand Down Expand Up @@ -3081,25 +3079,19 @@ describe('@connection', () => {
{ a: 123 },
{ a: 234 },
{ a: 456 },
// Delivered again because we explicitly called resetLastResults.
{ a: 456 },
]);

expect(bResults).toEqual([
{ b: "asdf" },
{ b: "ASDF" },
{ b: "oyez" },
// Delivered again because we explicitly called resetLastResults.
{ b: "oyez" },
]);

expect(abResults).toEqual([
{ a: 123, b: "asdf" },
{ a: 234, b: "asdf" },
{ a: 234, b: "ASDF" },
{ a: 456, b: "oyez" },
// Delivered again because we explicitly called resetLastResults.
{ a: 456, b: "oyez" },
]);

expect(cResults).toEqual([
Expand Down
4 changes: 3 additions & 1 deletion src/core/QueryInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ export class QueryInfo {
setDiff(diff: Cache.DiffResult<any> | null) {
const oldDiff = this.diff;
this.diff = diff;
if (!this.dirty && diff?.result !== oldDiff?.result) {
if (!this.dirty &&
!equal(oldDiff && oldDiff.result,
diff && diff.result)) {
this.dirty = true;
if (!this.notifyTimeout) {
this.notifyTimeout = setTimeout(() => this.notify(), 0);
Expand Down

0 comments on commit 6c4280e

Please sign in to comment.