Skip to content

Commit 5e8ec56

Browse files
committed
Merge remote-tracking branch 'origin/main' into release-4.0
2 parents 32e85ea + d0cac27 commit 5e8ec56

File tree

6 files changed

+117
-15
lines changed

6 files changed

+117
-15
lines changed

.circleci/config.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131

3232
Lint:
3333
docker:
34-
- image: cimg/node:23.7.0
34+
- image: cimg/node:23.9.0
3535
steps:
3636
- checkout
3737
- run: npm version
@@ -40,15 +40,15 @@ jobs:
4040

4141
Formatting:
4242
docker:
43-
- image: cimg/node:23.7.0
43+
- image: cimg/node:23.9.0
4444
steps:
4545
- checkout
4646
- run: npm ci
4747
- run: npm run check:format
4848

4949
Tests:
5050
docker:
51-
- image: cimg/node:23.7.0
51+
- image: cimg/node:23.9.0
5252
parameters:
5353
project:
5454
type: string
@@ -70,15 +70,15 @@ jobs:
7070
path: reports/junit
7171
Attest:
7272
docker:
73-
- image: cimg/node:23.7.0
73+
- image: cimg/node:23.9.0
7474
steps:
7575
- checkout
7676
- run: npm ci
7777
- run: npm run test:type-benches
7878

7979
BuildTarball:
8080
docker:
81-
- image: cimg/node:23.7.0
81+
- image: cimg/node:23.9.0
8282
steps:
8383
- checkout
8484
- run: npm run ci:precheck
@@ -97,7 +97,7 @@ jobs:
9797
react:
9898
type: string
9999
docker:
100-
- image: cimg/node:23.7.0-browsers
100+
- image: cimg/node:23.9.0-browsers
101101
steps:
102102
- checkout
103103
- attach_workspace:
@@ -138,7 +138,7 @@ jobs:
138138
externalPackage:
139139
type: string
140140
docker:
141-
- image: cimg/node:23.7.0
141+
- image: cimg/node:23.9.0
142142
steps:
143143
- checkout
144144
- attach_workspace:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,12 @@
471471

472472
- [#12384](https://github.com/apollographql/apollo-client/pull/12384) [`6aa6fd3`](https://github.com/apollographql/apollo-client/commit/6aa6fd316cfdb31ebbe3e3133cca2965604e7ca1) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Don't emit a partial cache result from `cache-only` queries when `returnPartialData` is `false`.
473473

474+
## 3.13.5
475+
476+
### Patch Changes
477+
478+
- [#12461](https://github.com/apollographql/apollo-client/pull/12461) [`12c8d06`](https://github.com/apollographql/apollo-client/commit/12c8d06f1ef7cfbece8e3a63b7ad09d91334f663) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Fix an issue where a `cache-first` query would return the result for previous variables when a cache update is issued after simultaneously changing variables and skipping the query.
479+
474480
## 3.13.4
475481

476482
### Patch Changes

docs/source/_sidebar.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ items:
3535
href: ./data/error-handling
3636
- label: Document transforms
3737
href: ./data/document-transforms
38+
- label: Deferring response data
39+
href: ./data/defer
3840
- label: Best practices
3941
href: ./data/operation-best-practices
4042
- label: Caching

docs/source/data/defer.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: "Using the @defer directive in Apollo Client"
33
description: Receive query response data incrementally
4+
minVersion: 3.7.0
45
---
56

67
> **The `@defer` directive is currently at the [General Availability stage](/resources/product-launch-stages/#general-availability) in Apollo Client, and is available by installing `@apollo/client@latest`.** If you have feedback on it, please let us know via [GitHub issues](https://github.com/apollographql/apollo-client/issues/new?assignees=&labels=&template=bug.md).

src/core/QueryInfo.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export class QueryInfo {
7474
variables?: Record<string, any>;
7575
stopped = false;
7676

77+
private cancelWatch?: () => void;
7778
private cache: ApolloCache;
7879

7980
constructor(
@@ -103,6 +104,8 @@ export class QueryInfo {
103104
}): this {
104105
if (!equal(query.variables, this.variables)) {
105106
this.lastDiff = void 0;
107+
// Ensure we don't continue to receive cache updates for old variables
108+
this.cancel();
106109
}
107110

108111
Object.assign(this, {
@@ -283,20 +286,17 @@ export class QueryInfo {
283286

284287
// Cancel the pending notify timeout
285288
this.reset();
286-
287289
this.cancel();
288-
// Revert back to the no-op version of cancel inherited from
289-
// QueryInfo.prototype.
290-
this.cancel = QueryInfo.prototype.cancel;
291290

292291
const oq = this.observableQuery;
293292
if (oq) oq.stopPolling();
294293
}
295294
}
296295

297-
// This method is a no-op by default, until/unless overridden by the
298-
// updateWatch method.
299-
private cancel() {}
296+
private cancel() {
297+
this.cancelWatch?.();
298+
this.cancelWatch = void 0;
299+
}
300300

301301
private lastWatch?: Cache.WatchOptions;
302302

@@ -317,7 +317,7 @@ export class QueryInfo {
317317

318318
if (!this.lastWatch || !equal(watchOptions, this.lastWatch)) {
319319
this.cancel();
320-
this.cancel = this.cache.watch((this.lastWatch = watchOptions));
320+
this.cancelWatch = this.cache.watch((this.lastWatch = watchOptions));
321321
}
322322
}
323323

src/react/hooks/__tests__/useQuery.test.tsx

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,99 @@ describe("useQuery Hook", () => {
15051505

15061506
await expect(takeSnapshot).not.toRerender();
15071507
});
1508+
1509+
// https://github.com/apollographql/apollo-client/issues/12458
1510+
it("returns correct result when cache updates after changing variables and skipping query", async () => {
1511+
interface Data {
1512+
user: {
1513+
__typename: "User";
1514+
id: number;
1515+
name: string;
1516+
};
1517+
}
1518+
1519+
const query: TypedDocumentNode<Data, { id: number }> = gql`
1520+
query ($id: ID!) {
1521+
user(id: $id) {
1522+
id
1523+
name
1524+
}
1525+
}
1526+
`;
1527+
1528+
const client = new ApolloClient({
1529+
link: ApolloLink.empty(),
1530+
cache: new InMemoryCache(),
1531+
});
1532+
1533+
using _disabledAct = disableActEnvironment();
1534+
const { takeSnapshot, rerender } = await renderHookToSnapshotStream(
1535+
({ id, skip }) => useQuery(query, { skip, variables: { id } }),
1536+
{
1537+
initialProps: { id: 1, skip: true },
1538+
wrapper: ({ children }) => (
1539+
<ApolloProvider client={client}>{children}</ApolloProvider>
1540+
),
1541+
}
1542+
);
1543+
1544+
await expect(takeSnapshot()).resolves.toEqualQueryResult({
1545+
data: undefined,
1546+
error: undefined,
1547+
called: false,
1548+
loading: false,
1549+
networkStatus: NetworkStatus.ready,
1550+
previousData: undefined,
1551+
variables: { id: 1 },
1552+
});
1553+
1554+
client.writeQuery({
1555+
query,
1556+
variables: { id: 1 },
1557+
data: { user: { __typename: "User", id: 1, name: "User 1" } },
1558+
});
1559+
await rerender({ id: 1, skip: false });
1560+
1561+
await expect(takeSnapshot()).resolves.toEqualQueryResult({
1562+
data: { user: { __typename: "User", id: 1, name: "User 1" } },
1563+
called: true,
1564+
loading: false,
1565+
networkStatus: NetworkStatus.ready,
1566+
previousData: undefined,
1567+
variables: { id: 1 },
1568+
});
1569+
1570+
await rerender({ id: 2, skip: true });
1571+
1572+
await expect(takeSnapshot()).resolves.toEqualQueryResult({
1573+
data: undefined,
1574+
error: undefined,
1575+
called: false,
1576+
loading: false,
1577+
networkStatus: NetworkStatus.ready,
1578+
previousData: { user: { __typename: "User", id: 1, name: "User 1" } },
1579+
variables: { id: 2 },
1580+
});
1581+
1582+
client.writeQuery({
1583+
query,
1584+
variables: { id: 2 },
1585+
data: { user: { __typename: "User", id: 2, name: "User 2" } },
1586+
});
1587+
1588+
await rerender({ id: 2, skip: false });
1589+
1590+
await expect(takeSnapshot()).resolves.toEqualQueryResult({
1591+
data: { user: { __typename: "User", id: 2, name: "User 2" } },
1592+
called: true,
1593+
loading: false,
1594+
networkStatus: NetworkStatus.ready,
1595+
previousData: { user: { __typename: "User", id: 1, name: "User 1" } },
1596+
variables: { id: 2 },
1597+
});
1598+
1599+
await expect(takeSnapshot).not.toRerender();
1600+
});
15081601
});
15091602

15101603
it("can provide options.client without ApolloProvider", async () => {

0 commit comments

Comments
 (0)