Skip to content

Commit

Permalink
Avoid using stale last.result in getCurrentResult.
Browse files Browse the repository at this point in the history
This fixes #7978 in a better way than #8422, by actually checking
whether the `last.variables` used for `last.result` are still equal to
the current `options.variables`, before reusing `last.result` in
`ObservableQuery#getCurrentResult`.
  • Loading branch information
benjamn committed Aug 16, 2021
1 parent 8062a48 commit 8b60b29
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/core/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ export class ObservableQuery<
}

public getCurrentResult(saveAsLastResult = true): ApolloQueryResult<TData> {
const lastResult = this.getLastResult();
// Use the last result as long as the variables match this.variables.
const lastResult = this.getLastResult(true);

const networkStatus =
this.queryInfo.networkStatus ||
Expand Down
2 changes: 1 addition & 1 deletion src/core/__tests__/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ describe('ObservableQuery', () => {
expect(result.errors).toEqual([error]);
expect(observable.getCurrentResult().errors).toEqual([error]);
observable.setVariables(differentVariables);
expect(observable.getCurrentResult().errors).toEqual([error]);
expect(observable.getCurrentResult().errors).toBeUndefined();
} else if (handleCount === 2) {
expect(result.data).toEqual(dataTwo);
expect(observable.getCurrentResult().data).toEqual(
Expand Down

0 comments on commit 8b60b29

Please sign in to comment.